Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在visualc+中组织文件+;项目 我在Visual C++ 2010 Express版中写了一个项目。在我尝试在项目中添加新的源文件之前,一切都很好。然后,当我试图包含一个头文件时,编译器说在这个头文件中声明的类在包含相同头文件的其他源文件中找不到_C++_C Preprocessor - Fatal编程技术网

在visualc+中组织文件+;项目 我在Visual C++ 2010 Express版中写了一个项目。在我尝试在项目中添加新的源文件之前,一切都很好。然后,当我试图包含一个头文件时,编译器说在这个头文件中声明的类在包含相同头文件的其他源文件中找不到

在visualc+中组织文件+;项目 我在Visual C++ 2010 Express版中写了一个项目。在我尝试在项目中添加新的源文件之前,一切都很好。然后,当我试图包含一个头文件时,编译器说在这个头文件中声明的类在包含相同头文件的其他源文件中找不到,c++,c-preprocessor,C++,C Preprocessor,这是构建的输出。我在每个头文件中添加了#pragma消息,以查看它何时被包含 1>------ Build started: Project: OSGF, Configuration: Debug Win32 ------ 1> OSGFComponentManager.cpp 1> OSGFComponentManager.h included 1> OSGFComponent.h included 1> Game.h includ

这是构建的输出。我在每个头文件中添加了
#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 ==========  

我猜包含OSGFComponent定义的标题必须在包含osgfdrawablecomponent.h之前包含在osgfdrawablecomponent.h或OSGFComponentManager.cpp中,然后才能包含osgfdrawablecomponent.h

您是否在osgfdrawablecomponent.h

头文件中包含了OSGFComponent.hGame.h。当我从OSGFComponentManager.cpp中删除#include“OSGFComponentManager.h”时,代码工作正常。当您的声明位于头文件(.h)中时,代码工作正常吗?如果您在cpp文件中只有实现,那么这是不可能的。或者,OSGFComponentManager.h包含在OSGFComponentManager.cpp中的其他头文件中?还有,你在使用#ifdef-#define-#endif宏吗?如果代码不是很长的话,我建议你将代码发布在这里,因为我们所能做的只是在黑暗中拍摄,而看不到你的源代码。这是源代码。我还注释了OSGFComponentManager.cpp中的所有方法定义,我还没有使用这个类。在“ScreenText.h”和“osgfcomponent.h”中包括“game.h”,同时在“OSGFComponentManager.cpp”中取消注释所有函数体,否则会出现链接错误。另外,不需要转发声明(作为类游戏;当您包含header Game.h时)。删除此类OSGFComponent*dummy;在osgfdrawablecomponent.h中。编译此文件并给我新的错误:)