2011-12-27 84 views
2

由于某些原因我得到多个错误一旦我包含我自己的头文件,它有一个简单的类定义。下面是代码:包括标题导致错误

#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)

回答

7

您在.h文件中的类定义之后缺少一个分号。

+0

哎呀,错过了..谢谢 – 2011-12-27 03:25:52

2

除了缺少分号dasblinkenlight指出的那样,你也初始化从方法一员,是不是构造函数,在这里:

CInt::CDirect3DDevice(int x) : k(x) {}; 

这将导致错误,因为成员可能只使用: k(x)语法类'ctor,而不是其他方法。

这看起来像是一个复制粘贴编辑错误,但没有发布错误信息,因此无法确定。