由于某种原因,一旦我包含我自己的头文件,我就会得到多个错误,这个头文件有一个简单的类定义。这是代码:
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
//#include "CInt.h" <--- i get multiple errors once i activate this line
HINSTANCE hInst;
HWND wndHandle;
bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if (!initWindow(hInstance)) return false;
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while(true)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT) break;
}
return msg.wParam;
}
bool initWindow(HINSTANCE hInstance )
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(0, IDI_APPLICATION);
wcex.hCursor = LoadCursor(0, IDC_ARROW);
wcex.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
wcex.lpszMenuName = 0L;
wcex.lpszClassName = L"MOVEENGINE";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
wndHandle = CreateWindow(L"MOVEENGINE", L"MOVE ENGINE", WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, 0, 0, 1920, 1080, NULL, NULL, hInstance, NULL);
if (!wndHandle) return false;
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int iVirtKey = static_cast<int>(wParam);
switch (message)
{
case WM_KEYDOWN:
switch(iVirtKey)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
也是CInt.h
的代码:
class CInt
{
public:
int k;
CDirect3DDevice(int x):k(x){};
}
我的代码出了什么问题? (我使用Visual Studio 2010)
答案 0 :(得分:7)
您的.h文件中的类定义后缺少分号。
答案 1 :(得分:2)
除了缺少分号dasblinkenlight指出,你还要从一个不是构造函数的方法初始化一个成员,在这里:
CInt::CDirect3DDevice(int x) : k(x) {};
这会导致错误,因为成员只能使用类'ctor中的: k(x)
语法,而不能使用其他方法。
这看起来可能是复制粘贴编辑错误,但如果没有发布您收到的错误,就无法确定。