VC++ 在两个文件互相包含时会出现的错误(4)
-------------------------------------------------------------------------------- 做法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'"
- 上一篇:VC++6.0写的等待提示
- 下一篇:使用VC++6.0制作ASP服务器控件简介