I want to start a struct method in an own thread:
g_thread_new( "NewThread", mymethod , NULL)
The problem is, the program only compiles if I set the method to "static":
static gpointer mymethod(gpointer nrp) { puts(this->mystring) ; ... }
But if I set the method to "static" I cannot access the struct instance variables like this->mystring.
Is there a way to use g_thread_new with class methods AND access instance variables?
What you can and should do is receive a void*
in your static function as a parameter from the thread. That void*
is the object that you want it's function called. Just cast it to the object's type and call the method.
Also, consider using boost::thread
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.