此问题困扰我了很久,在网上大致查找了下相关说明。目前定位问题与定义的include的顺序有关
比如我在头文件定义集成的头文件中有如下定义
sdafx.h
#include "test.h"
#include "another.h"
test.h
#include "sdafx.h"
class test
{
test();
};
another.h
#include "sdafx.h"
class another
{
test *p;
another();
};
这样是没有问题的,因为在sdafx.h中,编译时预先载入了test类,以至another类在引用test类型指针时可以找到对应的内存结构。
但是如果我们把include顺序调转过来,编译时就会出现 error C2143: syntax error : missing ';' before '*'错误
解决方式
一,整理include的头文件顺序
二,如果目标类中引用的类对象过多,可以在类定义前声明要引用的类成员。
#include "sdafx.h"
class test;
class another
{
test *p;
another();
};