code:
// create class instance
MC_THREAD MTHR;
// set some values in the class
MTHR.setup_mc_thread("com6", &es);
// create an thread to run the non-static member function
std::thread MCTHR(MC_THREAD::start_mc_thread, std::ref(MTHR));
the definition of the function is:
void MC_THREAD::start_mc_thread(){
while(1){
//do_stuff
}
}
The above code compiles (and works correctly) on windows 8 & 10 using TDM-GCC compiler based on gcc 5.1.0.
The above code generates the following error with gcc 7.3.1 on linux:
error: invalid use of non-static member function ‘void MC_THREAD::start_mc_thread()’|
The machine which generates the error is running fedora 27 using gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Any suggestions would be appreciated!
Solved: See Sam's Comment Below
Also had to link pthread.
std::threadto execute a class method requires the first parameter to be a plain pointer, i.e.this, and not a reference. Change the parameter to simply&MTHR. - Sam Varshavchik