我试图在父类中声明一个静态类并对其进行初始化,但我似乎遇到了各种错误。
/* MainWindow.h */
class MainWindow
{
private:
static DWORD WINAPI threadproc(void* param);
static MainWindow *hWin;
};
/* MainWindow.cpp */
#include "MainWindow.h"
void MainWindow::on_pushButton_clicked()
{
HANDLE hThread = CreateThread(NULL, NULL, threadproc, (void*) this, NULL, NULL);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
DWORD WINAPI MainWindow::threadproc(void* param)
{
hWin = (MainWindow*) param;
//Be able to access stuff like hWin->run();
return 0;
}
我尝试使用 MainWindow::hWin = (MainWindow*) param;
和 MainWindow::hWin = new MainWindow((MainWindow*) param));
和许多其他人,但似乎都没有用。这样做的正确方法是什么?关于这个主题,有没有人可以推荐任何资源,我已经为 class
问题纠结了几天,非常沮丧。
最佳答案
关于c++ - 在 C++ 类中初始化静态数据成员(类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9413218/