编译错误:missing type specifier - int assumed. Note: C++ does not support default-in

chen16501560 2012-05-30 01:20:05
编译错误:
1>file1.cpp
1>e:\代码\test\test\file2.hpp(8) : error C2143: syntax error : missing ')' before '*'
1>e:\代码\test\test\file2.hpp(8) : error C2143: syntax error : missing ';' before '*'
1>e:\代码\test\test\file2.hpp(8) : error C2460: 'B::A' : uses 'B', which is being defined
1> e:\代码\test\test\file2.hpp(7) : see declaration of 'B'
1>e:\代码\test\test\file2.hpp(8) : error C2059: syntax error : ')'
1>e:\代码\test\test\file2.hpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\代码\test\test\file2.hpp(8) : error C2473: 'a' : looks like a function definition, but there is no parameter list.
1>e:\代码\test\test\file2.hpp(9) : error C2059: syntax error : '}'
1>e:\代码\test\test\file2.hpp(9) : error C2143: syntax error : missing ';' before '}'
1>e:\代码\test\test\file2.hpp(9) : error C2059: syntax error : '}'


源码:


file1.hpp文件:
#include "file2.hpp"

struct A
{
A(){};
};
file2.hpp文件

#include "file1.hpp"

struct B
{
B(A* a){};
};



最近在编码的时候突然出现了一堆类似的错误,后来去掉一个头文件后就好了,最后整理了下,大概和上述代码一样类似的错误,将file1.hpp文件中的#include "file2.hpp" 去掉后就好了。请教下,这是为什么。
...全文
317 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wZi 2012-05-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

循环定义?不怎么懂?

我知道file1.hpp文件里#include "file2.hpp"完全没必要 ,但有时头文件太多了,一部小心就包含进去了,像我这次发现这错误的时候一样。
[/Quote]

#include "A"实际上你可以理解成 拷贝 A的代码进来

那你上面写的程序

编译器运行到A的时候

#include "file2.hpp"

struct A
{
A(){};
};
file2.hpp文件

#include "file1.hpp"

struct B
{
B(A* a){};
};


#include "file2.hpp"

所以他跳到
FILE2了

然后在FILE2里面又发现
#include "file1.hpp"
有包含FILE1了

所以他又跳到了FILE1。
这样的话就会一直repeat
chen16501560 2012-05-30
  • 打赏
  • 举报
回复
你说的这个
#ifndef xxx
#define xxx



#endif

我肯定是有写了的
chen16501560 2012-05-30
  • 打赏
  • 举报
回复
循环定义?不怎么懂?

我知道file1.hpp文件里#include "file2.hpp"完全没必要 ,但有时头文件太多了,一部小心就包含进去了,像我这次发现这错误的时候一样。
wZi 2012-05-30
  • 打赏
  • 举报
回复
#ifndef xxx
#define xxx



#endif

哥们,重复包含了。死循环了

加个头吧
prohibit 2012-05-30
  • 打赏
  • 举报
回复
file1.hpp文件里#include "file2.hpp"完全没必要,其他地方要用时,直接#include "file2.hpp"就行了
W170532934 2012-05-30
  • 打赏
  • 举报
回复
循环。你这样循环的定义。我想问你这个到底是A先还是B先呢??

65,183

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧