类内用多线程函数时候提示需要使用静态成员。
由于我不希望用静态成员。于是翻了很多文章。 利用线程函数的参数要做文章。
线程函数原型
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpsa,
DWORD lpsa,
DWORD lpsa,
DWORD cbStack,
LPTHREAD_START_ROUTINE cbStack,
LPTHREAD_START_ROUTINE lpStartAddr,
LPVOID lpStartAddr,
LPVOID lpvThreadParam,
DWORD lpvThreadParam,
DWORD fdwCreate,
LPDWORD fdwCreate,
LPDWORD lpIDThread
);
传入函数原型
DWORD ThreadProc( LPVOID lpParameter);
方法如下
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
class cMyClass
2![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
3
public:
4
DWORD ThreadProc();
5
protected:
6
private:
7![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
static DWORD __stdcall _ThreadPorc(LPVOID lpVoid)
{return ((cMyClass*)lpVoid)->ThreadProc(); }
8
};
9![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
10
DWORD cMyClass::ThreadProc()
11![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
12
//Code![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/dot.gif)
13
}
这样的话就可以使用非静态的类函数。。