头文件交叉定义出现--GetDocument missing storage-class or type specifiers错误的解决方法

来源:互联网 发布:微信闪退修复软件 编辑:程序博客网 时间:2024/06/05 06:22

GetDocument missing storage-class or type specifiers的解决方法

error C2143: syntax error : missing ';' before '*'
error C2501: 'CTest1Doc' : missing storage-class or type specifiers
error C2501: 'GetDocument' : missing storage-class or type specifiers
遇到这种莫名的错误,最可气了。
当我在childFrm中加入 #include "CMyView.h"便报的错

解决方法1是:
是在自己要使用的View类的.cpp文件中加入下面一句声明:
class CMyDoc;

解决方法2是:

是在自己要使用的View类的.cpp文件
#include   "XXXDoc.h"    
#include   "XXXView.h"   
#include   "MainFrm.h" 


具体的,可以拿三峡(周达超编的)应用程序来说明~~

CPlatformGL这个类中,要用到CModuleGL这个类,

CModuleGL这个类,也要用到CPlatformGL这个类, 如果正常的在头文件交叉包含的话,很容易出现上面描述的编译问题,

解决方法1:

CPlatformGL这个类的头文件中,加上#include "ModuleGL.h"

另外,还有在整个类的定义前,加上class CModuleGL;   //类声明,避免交叉定义

(我看到周达超程序还在类定义前,加上了using namespace std;//命名空间,不知道和这个有没有关系)

同样的,

CModuleGL这个类的头文件中,加上#include "PlatFormGL.h",

在类的定义前,加上class CModuleGL;


三峡程序的第二个例子~~

在SXSystem这个类中,需要获取视图类CSXS_testView类的指针(即,要用到视图类),

在视图类中也要调用SXSystem类,如实就有下面的解决方法~~

解决方法2:

SXSystem类的源文件(*.cpp文件,而不是*.h)中,包含了三个文件,如下:

#include "MainFrm.h"
#include "SXS_testDoc.h"
#include "SXS_testView.h"

而在视图类中,只需在头文件包含SXSystem类即可,即#include "SXSystem.h"


以上是两种常规的解决方法,都很好用~~(用第一种较多)





1 0
原创粉丝点击