Consider this:
I have the class foo, with the public method thread(), and the private method bar()
In the thread() method, I would like to create a new thread, using pthread_create( ), that points to bar().
Could someone tell me how to do this? I have the following code:
I get the following error message (line 16):
argument of type ‘void* (foo::)(void*)’ does not match ‘void*’
I have the class foo, with the public method thread(), and the private method bar()
In the thread() method, I would like to create a new thread, using pthread_create( ), that points to bar().
Could someone tell me how to do this? I have the following code:
Code:
#include <iostream>
#include <pthread.h>
using namespace std;
class foo
{
public:
foo()
{
}
void thread()
{
void* g;
g = this->bar;
pthread_t thread1;
char* whatever = "hello";
pthread_create( &thread1,
NULL,
&g,
static_cast<void*>(whatever)
);
}
private:
void* bar(void* arg)
{
cout << "Whatever" << endl;
}
};
int main()
{
foo New;
New.thread();
return 0;
}
argument of type ‘void* (foo::)(void*)’ does not match ‘void*’
Comment