这个错误还可能导致以下错误:
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- error C2061
查阅文档msdn发现:

- 导致这种错误的可能有一下一些情况:
- 在不该加分号的地方加分号
- 在该加分号的地方不加分号
- 头文件循环包含
这边就讲一下我遇到的第三个情况
- 我在helper.h头文件中定义了一个类,它其中又要用到imp.h中的类,而imp.h中又用到helper.h中的一个类,如果是这种情况,我们头文件包含这样写:
//helper.h
#include "imp.h"
...blablabla...
//imp.h
#include "helper.h"
...blabla...
- 这样的话就会造成上面的错误
- 这是上面原因呢?
- 因为编译的时候,编译到helper.h,它就要去找imp.h包含进来,这时要编译imp.h就要找helper.h包含进来,这样就会实现一个死循环,编译失败,造成上面的错误。
- 怎么解决呢
- 在某一个头文件中申明要用的类
- 比如在imp.h中实际上要用到helper.h中的类是test类,我们应该这样做,使用前置声明占位:
//imp.h
//不用include helper.h了
class test;
//imp.cpp
//在cpp文件中include
#include "helper.h"
- 在imp.h中声明一下,就可用,不用包含头文件,在真正需要包含的cpp文件中包含即可。