Below is the code
#include <iostream>
#include <pthread.h>
using namespace std;
class Base
{
private:
public:
void *threadCall1( void * value)
{
cout<<"inside threadCall1"<<endl;
}
protected:
};
class Derived
{
private:
public:
void *threadCall2 ();
protected:
};
void *Derived::threadCall2()
{
cout<<"inside threadCall2"<<endl;
}
int main ()
{
int k = 2;
pthread_t t1;
cout<<"inside main"<<endl;
Base *b = new Base();
pthread_create(&t1,NULL,&b->threadCall1,(void *)k);
return 0;
}
Error
main.cc: In function
int main()': main.cc:46: error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say&Base::threadCall1' main.cc:46: error: cannot convertvoid*(Base::*)(void*)' tovoid*()(void)' for argument3' toint pthread_create(pthread_t*, const pthread_attr_t*, void*()(void), void*)'
I agree C++ forbids this call but is there any way I can call a class member function using posix thread