about using pthread in cpp
i just want to put *pthred_create* , *pthread_join* into one class,
but i do not know how to, anyone help me?
the code below is mine:
------------------------------
#include <pthread.h>
#include <iostream>
using namespace std;
class CppThread{
public:
CppThread():num(0),slp(3){}
CppThread(int n,int s):num(n),slp(s){}
void create(){
typedef void* (CppThread::*RUN)(void*);
RUN r=&CppThread::run;
pthread_create(&tid,NULL,(mem_fun(run),r),new int(num));
}
void join(){
if(tid){
pthread_join(tid,NULL);
}
}
private:
pthread_t tid;
int num;
int slp;
void* run(void *i){
sleep(slp);
cout<< "Thread num : " << num <<" \ti:"<< *(static_cast<int*>(i)) << endl;
delete static_cast<int*>(i);
}
};
int main(int argc,char*argv[]){
CppThread ct1(1,10);
CppThread ct2(2,5);
ct1.create();
ct2.create();
ct1.join();
ct2.join();
}
-------------------------------
i compile it with g++,and the msg is:
kdr2@kdr2-pc:~/work/by_lang/c_cpp/stdhk$ g++ cppthread.cpp
cppthread.cpp: In member function ???void CppThread::create()???:
cppthread.cpp:14: ????????? argument of type ???void* (CppThread::)(void*)??? does not match ???void* (CppThread::*)(void*)???
kdr2@kdr2-pc:~/work/by_lang/c_cpp/stdhk$
i think the type [void* (CppThread::)(void*)] and [void* (CppThread::*)(void*)] is the same one,aren't them?
--
http://kdr2.net
------yours Killy Draw