The above answers are good, but in my case the 1st approach, which converts the function to static, does not work. I tried to convert the exit code to go into a stream function, but this code had many references to non-static members of the class. The second solution for encapsulating a C ++ object works, but has 3-level shells to start the stream.
I had an alternative solution that uses the existing C ++ construct - the "friend" function, and it worked fine for my case. An example of how I used a βfriendβ (will use the same example for names, showing how it can be converted to a compact form using a friend)
class MyThreadClass { public: MyThreadClass() {} virtual ~MyThreadClass() {} bool Init() { return (pthread_create(&_thread, NULL, &ThreadEntryFunc, this) == 0); } void WaitForThreadToExit() { (void) pthread_join(_thread, NULL); } private:
Of course, we can use boost :: thread and avoid all of these, but I tried to change the C ++ code so as not to use boost (the code was connected with boost for this purpose)
sanmara Jul 17 '15 at 20:21 2015-07-17 20:21
source share