简体   繁体   中英

Organizing files in Visual C++ project

I'm writing a project in Visual C++ 2010 Express edition. Everything was fine before I tried to add new source file in the project. Then when I tried to include one of the header files the compiler said that the class declared in this header is not found in other source file which includes the same header file.

This is output from build. I've added #pragma message in each header file to see when it is included.

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 ==========  

我猜包含OSGFComponent定义的标头必须在包含osgfdrawablecomponent.h之前包含在osgfdrawablecomponent.h或OSGFComponentManager.cpp中

您是否在osgfdrawablecomponent.h头文件中包含OSGFComponent.hGame.h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM