0

I am working on a C++ chat. I have a class which starts the server and I need to create a thread which handles all incoming connections and one that handles messages from each of the clients.

I need to start it from within the class so that I am also able to access the members of the class, but it is impossible with the CreateThread function since it does not handle the predefined first parameter (this) for class member functions.

I have previously written one by passing a struct with pointers to everything I needed but it was such a pain in the ass to write and fix everything while debugging so I am wondering if there is anything I can use that allows me to start it from within the class and be able to access the member functions and variables.

Thanks!

dksue
  • 61
  • 3
  • 1
    related/dupe: https://stackoverflow.com/questions/10673585/start-thread-with-member-function – NathanOliver Mar 19 '20 at 17:45
  • Re, "I need to start it from within the class so that I am also able to access the members of the class." Either that or, you need to re-factor your code so that you can pass each thread a pointer or a reference to some object that contains everything it needs. – Solomon Slow Mar 19 '20 at 18:01
  • As I said a little lower in the text, I have already did that but it's painful to write all that, so I am currently looking into using std::asyc as some other user suggested here, but his comment was deleted for some reason – dksue Mar 19 '20 at 18:08

0 Answers0