我在头文件中声明属性WNDCLASSEX wc
,如下所示:
private:
HWND hWnd;
LPDIRECT3D9 g_pD3D; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice; // Our rendering device
WNDCLASSEX wc;
我想在我的Init()函数中初始化它,如下所示:
void RAT_RendererDX9::Init(RAT_WindowManager* argWMan)
{
wMan = argWMan;
// Register the window class
wc =
{
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0, 0,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
"D3D Tutorial", NULL
};
RegisterClassEx( &wc );
hWnd = CreateWindow( "", "abc", WS_OVERLAPPEDWINDOW, 10, 10, 20, 20,
NULL, NULL, wc.hInstance, NULL );
g_pD3D = (LPDIRECT3D9)Direct3DCreate9( D3D_SDK_VERSION );
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice );
}
但是,由于它,我收到以下错误:
1> e:\ rat_engine \ rat_engine \ rat_engine \ rat_rendererdx9.cpp(18):错误 C2059:语法错误:'{'
1> e:\ rat_engine \ rat_engine \ rat_engine \ rat_rendererdx9.cpp(18):错误 C2143:语法错误:缺少';'在'{'
之前1> e:\ rat_engine \ rat_engine \ rat_engine \ rat_rendererdx9.cpp(19):错误 C3867:'RAT_ENGINE :: RAT_RendererDX9 :: MsgProc':缺少函数调用 参数列表;使用'& RAT_ENGINE :: RAT_RendererDX9 :: MsgProc'创建一个 指向成员的指针
1> e:\ rat_engine \ rat_engine \ rat_engine \ rat_rendererdx9.cpp(22):错误 C2143:语法错误:缺少';'在'}'之前
但我几乎从教程中复制了初始化,唯一的例外是在WinMain()函数中初始化了wc,而不是Init()函数。
为什么它不起作用,我该如何解决?
答案 0 :(得分:3)
该语法适用于复制初始化聚合,但您的实际上是赋值。当您执行wc
类的构造函数时,对象RAT_RendererDX9
会被默认构造。
Init
函数中的赋值实际上与此相同:
wc.operator = (...);
如果您想使用该语法,可以尝试将分配更改为以下内容:
WNDCLASSEX wndClass =
{
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0, 0,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
"D3D Tutorial", NULL
};
wc = wndClass;
答案 1 :(得分:0)
WNDCLASSEX wndClass = { NULL };