我写了一个可以在另一个线程中做一些工作的类:
class SkeData
{
public:
SkeData(INuiSensor* pSensor);
~SkeData();
HANDLE StartSaveSkeData_Frames(int nFrames = 1);
HANDLE StartSaveSkeData2File_Frames(HANDLE hFile,int nFrames = 1);
[...]
private:
//Two thread functions
static DWORD WINAPI AddFrames(LPVOID lpParam);
static DWORD WINAPI AddFrames2File(LPVOID lpParam);
[...]
};
HANDLE SkeData::StartSaveSkeData_Frames(int nFrames)
{
[...]
m_hThread = CreateThread(NULL, 0, AddFrames, this, 0, NULL);
return m_hThread;
}
HANDLE SkeData::StartSaveSkeData2File_Frames(HANDLE hFile,int nFrames)
{
[...]
m_hThread = CreateThread(NULL, 0, AddFrames2File, this, 0, NULL);
return m_hThread;
}
DWORD WINAPI SkeData::AddFrames(LPVOID lpParam)
{
SkeData *This = (SkeData *)lpParam;
return This->Thread_AddFrames();
}
DWORD WINAPI SkeData::AddFrames2File(LPVOID lpParam)
{
SkeData *This = (SkeData *)lpParam;
return This->Thread_AddFrames2File();
}
When I built the program solution in VS2010, linking error came up like this:
SkeData.obj : error LNK2019: unresolved external symbol "private: unsigned long __thiscall SkeData::Thread_AddFrames2File(void)" (?Thread_AddFrames2File@SkeData@@AAEKXZ) referenced in function "private: static unsigned long __stdcall SkeData::AddFrames2File(void *)" (?AddFrames2File@SkeData@@CGKPAX@Z)
1>E:\***\DataCollection.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
但是,当我删除其中一个线程函数时,它可以成功构建。因此,我猜错误的原因是关于线程函数的。但是我还是不明白为什么不能在我的课堂上再增加一个线程函数???
我希望任何人都可以给出更多的解释。
谢谢!
更多:对不起,当我粘贴我的代码时出现问题。我确实实现了两个线程函数......如果我没有,错误不会是这样的,对吧?