当我包含它的标头时,为什么我的代码中会出现"use of undefined type"错误?
Why am I getting an "use of undefined type" error in my code, when I have the header for it included?
我正在学习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
。CCD_ 10函数返回指向CCD_ 11的指针。在这个主消息循环所在的Main.cpp
文件的顶部,我包含了包含InputManager
定义的头,即InputManager.h
。所以,我不太清楚为什么它说这是一个未定义的类型。
有人知道这个错误是怎么发生的吗?我第一次尝试在这些头文件中使用正向声明,我想这可能与这些有关?
我把整个代码按文件组织粘贴到Github上:https://gist.github.com/ryancole/5936795#file-主-cpp-L27
文件的名称正确,错误行在粘贴底部附近突出显示。
Game.h
正向声明全局命名空间中的class InputManager
,但真正的InputManager
类在命名空间GameEngine
中。
由于这两个声明位于不同的命名空间中,它们彼此独立,并且全局命名空间中的InputManger
保持为不完整类型。若要解决此问题,请将forward声明移到命名空间中。
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++ "error: use of overloaded operator '*' is ambiguous"似乎只有一场比赛
- C++ "Invalid use of 'this' in non-member function" ,
- 继承类时"invalid use of incomplete type ‘class tree_node_t’"
- C++14 遇到奇怪的"use of deleted function"错误
- 出现这种错误的原因是什么"invalid use of non-static data member "
- 模板类和'invalid use of incomplete type'错误
- "invalid use of incomplete type" .解决循环依赖关系
- 使用互斥锁和条件变量作为成员时如何修复"use of deleted function"?
- 构造函数导致"use of deleted function"错误
- 禁止显示"use of the 'X' attribute is a C++17 extension"警告
- 为什么包含标头会导致"use of auto before deduction of auto"错误?
- C++:避免"use of deleted function"错误
- VSCode 错误: "incorrect use of va_start"
- 为什么我会得到"Invalid use of :: (scope resolution operator)?"
- 如何修复库中的"invalid use of non-static member function" 导入另一个库
- 在C++中传递对象会产生'invalid use of non-static member'错误