我正在学习C ++,并试图使用Direct3D编写一个简单的游戏。在我的游戏项目中,我在整个游戏中使用一个名为的命名空间GameEngine
。我的游戏逻辑包含在名为的主类中Game
。那Game
类将有东西,像输入管理器和对象管理器的成员变量。这些将是私有成员,但是我在Game
类上有一个公共函数,该函数返回指向InputManager
该类的指针。这样,我可以告诉该程序在程序的InputManager
主PeekMessage
循环内处理窗口消息。
这是我的主要消息循环...
// 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
文件已正确命名,并且错误行在粘贴底部附近突出显示。
Game.h
forwardclass InputManager
在全局名称空间中声明a ,但实际InputManager
类在名称空间中GameEngine
。
由于这两个声明位于不同的命名空间中,因此它们彼此独立,并且InputManger
全局命名空间中的in仍然是不完整的类型。要解决此问题,请将前向声明移到名称空间中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句