代碼中已包含頭文件、EActorType 確已聲明,編譯仍報「undeclared identifier」或類似錯誤。
#include "ActorType.h" →「Go to Definition」/「Open Document」,若無法跳轉,說明路徑錯誤或未加入工程。// ActorType.h
#ifndef ACTOR_TYPE_H
#define ACTOR_TYPE_H
#if defined(ENABLE_ACTOR_SYSTEM) // 若未定義此宏,整個枚舉消失
enum EActorType { ... };
#endif
#endif
檢查編譯命令行是否帶 -DENABLE_ACTOR_SYSTEM 或 #define 在包含前。
// 定義在命名空間中
namespace Game { enum EActorType { ... }; }
// 使用時需
Game::EActorType type; // 或 using namespace Game;
class B; + 將 #include "B.h" 移至 .cpp。*.pch 重建。☐ 右鍵 #include 能否跳轉到頭文件?
☐ 頭文件路徑是否在 Additional Include Directories?
☐ 是否被 #if 宏條件編譯排除?
☐ 是否需要命名空間前綴?
☐ 是否存在循環包含?
☐ Clean + Rebuild 還報錯?
/showIncludes 編譯選項輸出包含樹。-H 參數顯示包含鏈。target_include_directories 管理路徑,避免手動配置漏項。「頭文件已包含」≠「編譯器看到了完整定義」,逐項驗證包含鏈是解決此類問題的金標準。