1

我正在学习 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,我包含了包含 的定义的标题,InputManagerInputManager.h. 所以,我不太清楚为什么它说这是一个未定义的类型。

有谁知道这个错误发生了什么?我第一次尝试在其中一些头文件中使用前向声明,我想这可能与这些有关?

我将按文件组织的整个代码粘贴在 Github 上:https ://gist.github.com/ryancole/5936795#file-main-cpp-L27

文件已正确命名,错误行在粘贴底部附近突出显示。

4

1 回答 1

2

Game.hclass InputManager forward在全局命名空间中声明了 a ,但真正的InputManager类在命名空间中GameEngine

由于这两个声明位于不同的命名空间中,它们彼此独立,并且InputManger全局命名空间中的 保持不完整的类型。要解决此问题,请将前向声明移动到命名空间中。

于 2013-07-05T20:19:36.873 回答