在 Win32 应用程序中使用 CreateThread() 创建线程时,出现此错误。 在 CreateThread(NULL,0,pSample->Resize(),NULL,0,NULL);它显示函数调用错误。
我确实有几个文件:
main.cpp
WinMain()
{
//Create sample
return Win32Appliaction::Run(&sample);
}
Win32Application.cpp
int Win32Application::Run(DXSample* pSample)
{
//Create Window
pSample->Init();
pSample->Render();
CreateThread(NULL,0,pSample->Resize,NULL,0,NULL);//error occurs
pSample->Destroy();
}
DXSample.h
class DXSample
{
public:
virtual void Init() =0; //and rest all functions
};
HelloTexture.h
class HelloTexture:public DXSample
{
public :
virtual void Init();//all other functions similarly
}
HelloTexture.cpp
void Hellotexture::Init()
{ //code
}
void Hellotexture::Resize()
{
//code
}
最佳答案
CreateThread 的参数 #2 必须是指向与 ThreadProc 匹配的函数的指针签名。您不能传递 pSample->Resize() 的结果(无效)或指向 Resize 函数本身的指针(因为这是一个非静态类成员函数)。此外,您可能希望使用::std::thread 而不是直接调用 WinApi。
关于c++ - Visual Studio 2015 “non-standard syntax; use ' &' to create pointer for member”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43113015/