C++ 11 Thread initialization with member functions compiling error [duplicate] C++ 11 Thread initialization with member functions compiling error [duplicate] multithreading multithreading

C++ 11 Thread initialization with member functions compiling error [duplicate]


You need a callable object taking no parameters, so

thread t3(&A::foo, &obj);

should do the trick. This has the effect of creating a callable entity which calls A::foo on obj.

The reason is that a non-static member function of A takes an implicit first parameter of type (possibly cv qualified) A*. When you call obj.foo() you are effectively calling A::foo(&obj). Once you know that, the above incantation makes perfect sense.