我正在用Visual C ++ 2010 Express版编写一个项目。在我尝试在项目中添加新的源文件之前,一切都很好。然后,当我尝试包含其中一个头文件时,编译器说在此头文件中声明的类在包含相同头文件的其他源文件中找不到。
这是build的输出。我在每个头文件中添加了#pragma
消息,以查看它何时被包含。
1>------ Build started: Project: OSGF, Configuration: Debug Win32 ------
1> OSGFComponentManager.cpp
1> OSGFComponentManager.h included
1> OSGFComponent.h included
1> Game.h included
1> GameTimer.h Included
1> ScreenText.h included
1> OSGFDrawableComponent.h icluded
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(7): error C2504: 'OSGFComponent' : base class undefined
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(10): error C2061: syntax error : identifier 'Game'
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(10): error C2065: 'game' : undeclared identifier
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(12): error C2614: 'OSGFDrawableComponent' : illegal member initialization: 'OSGFComponent' is not a base or member
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(16): error C2027: use of undefined type 'OSGFComponent'
1> d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(4) : see declaration of 'OSGFComponent'
1>d:\myprograms\osgf\osgf\screentext.h(11): error C2061: syntax error : identifier 'Game'
1> Generating Code...
1> Compiling...
1> Main.cpp
1> Test.h included
1> Game.h included
1> GameTimer.h Included
1> ScreenText.h included
1> OSGFDrawableComponent.h icluded
1> OSGFComponent.h included
1> Generating Code...
1> Compiling...
1> Test.cpp
1> Test.h included
1> Game.h included
1> GameTimer.h Included
1> ScreenText.h included
1> OSGFDrawableComponent.h icluded
1> OSGFComponent.h included
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
答案 0 :(得分:0)
我想在包含osgfdrawablecomponent.h之前,必须在osgfdrawablecomponent.h或OSGFComponentManager.cpp中包含包含OSGFComponent定义的头文件
答案 1 :(得分:0)
您是否在 osgfdrawablecomponent.h 标题文件中包含 OSGFComponent.h 和 Game.h ?