Similar to this question: Start thread with member function and this one: std::thread calling method of class
However I have the following:
#include <thread> #include <iostream> class myAbstractClass { public: virtual void myFunction() = 0;//abstract class } class myFirstClass : public myAbstractClass { public: void myFunction() { std::cout << "First class here";} } class mySecondClass : public myAbstractClass { public: void myFunction() { std::cout << "Second class here";} } Then I have to call myFunction() from a different place in a new thread, but the following does not compile (and I can't think of anything else to try):
public void callMemberFunctionInThread(myAbstractClass& myInstance) { std::thread myThread (&myAbstractClass::myFunction, myInstance); //supposed to call myInstance.myFunction() on myThread }
C2259 'myAbstractClass': cannot instantiate abstract classin filetuplelocated inC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include(line 199)std::ref(myInstance)?virtualif the derived classes are supposed to override it. Don't know if that works withstd::threadanyway.