#include<boost/thread/thread.hpp>
#include<boost/bind.hpp>
#include <boost/function/function0.hpp>
#include<iostream>
using namespace std;
class CThread
{
private:
unsigned long m_ThreadID;
int m_ThreadState; //the state of the thread
public:
CThread();
virtual ~CThread(){}
void Run();
void ThreadFunction(); //调用函数run()
void Start()
{
boost::function0<void> f=boost::bind(&CThread::ThreadFunction,this);
boost::thread thrd(f);
thrd.join();
} //Start to execute the thread 线程的执行入口,其调用ThreadFunction()函数,
int
GetThreadState(void){return m_ThreadState;}
int GetThreadID(void){return m_ThreadID;}
};
CThread::CThread()
{
m_ThreadID = 0;
m_ThreadState = 0;
Start();
}
void CThread::ThreadFunction()
{
Run();
}
void CThread::Run()
{
cout<<"i am a thread~~~~~~~";
}
int main()
{
CThread thrd1;
return 0;
}
//编译的时候出现这个问题:testcl1.cpp:(.text+0xb): undefined reference to `vtable for CThread' 原因原来是我没有实现我的析构函数。。。。