我正在學習C++,並試圖使用Direct3D編寫一個簡單的遊戲。在我的遊戲項目中,我在整個遊戲中使用了一個命名空間,名稱爲GameEngine
。我的遊戲邏輯包含在一個名爲Game
的主類中。 Game
類將具有諸如輸入管理器和對象管理器之類的成員變量。這些將是私人成員,但我在我的Game
類上有公共職能,該類返回指向InputManager
類的指針。這樣,我可以告訴InputManager
處理程序的主循環中的窗口消息。爲什麼我在代碼中使用「未定義類型」錯誤時,包含頭文件?
這裏是我的主消息循環...
// instanciate the game
GameEngine::Game game(windowRectangle.bottom, windowRectangle.right);
// initialize D3D
game.InitializeDirect3D(hWnd);
game.InitializePipeline();
// main game loop
while (true)
{
// check for received event messages
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
bool handled = false;
if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST)
{
handled = game.GetInputManager()->HandleMouseInput(&msg);
}
else if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST)
{
handled = game.GetInputManager()->HandledKeyboardInput(&msg);
}
else if (msg.message == WM_QUIT)
{
break;
}
if (handled == false)
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
}
// render the current frame
game.RenderFrame();
}
// tear down D3D
game.CleanDirect3D();
我得到一個錯誤,當我打電話GetInputManager
,雖然。它說我正在使用一個不明確的類型InputManager
。 GetInputManager
函數返回一個指向InputManager
的指針。在我的Main.cpp
文件的頂部,其中包含此主消息循環所在的文件,其中包含標頭,其中包含InputManager
的定義,即InputManager.h
。所以,我不太確定它爲什麼說這是一個未定義的類型。
有沒有人知道這個錯誤發生了什麼?我試圖在這些頭文件中首次使用前向聲明,我想也許它與這些有關?
我粘貼整個代碼,按文件組織,在Github這裏:https://gist.github.com/ryancole/5936795#file-main-cpp-L27
這些文件都是正確的和錯誤行被突出顯示附近的糊底。
謝謝!
它在GameEngine命名空間中,你有文件中使用GameEngine嗎? – Alex1985
通告包括 –
您的包含警衛使用[保留標識符](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)。 – chris