龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC++ 在两个文件互相包含时会出现的错误(4)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
-------------------------------------------------------------------------------- 做法4 --------------------------------------------------------- //在文件Object.h 中定义 #include "NewType.h" #i

     --------------------------------------------------------------------------------    做法4  ---------------------------------------------------------

//在文件Object.h 中定义

#include "NewType.h"

#ifndef _OBJECT_H

#define _OBJECT_H

//位置

class Object

{

public:

  NewType ToType();

};

#endif

//在文件NewType.h 中定义

#ifndef _NEWTYPE_H

#define _NEWTYPE_H

#include "Object.h"

class NewType : public Object

{

}

#endif

产生错误:

"error C2146: syntax error : missing ';' before identifier 'ToType'"

"error C2501: 'NewType' : missing storage-class or type specifiers"

原因是不能识别NewType类

解决方案:

于是在"位置"加上前向引用声明

class NewType;

编译通过

但采用此种做法,类的定义和实现部分不能为内联函数,或者报错

"error C2027: use of undefined type 'NewType'"

收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!
按钮 内容不能为空!
立刻说两句吧! 查看0条评论
精彩图集

赞助商链接