缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int---->解决方法
来源:互联网 发布:hdfs java api jar包 编辑:程序博客网 时间:2024/06/05 11:57
写了一个对应让其出的错误(其实也挺不容易的喔 )
错误如下:
1>d:\work\win32project\testeachotherclude\testeachotherclude\test2.h(9): error C2143: 语法错误 : 缺少“;”(在“*”的前面)
1>d:\work\win32project\testeachotherclude\testeachotherclude\test2.h(9): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\work\win32project\testeachotherclude\testeachotherclude\test2.h(9): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\work\win32project\testeachotherclude\testeachotherclude\test2.h(10): error C2061: 语法错误: 标识符“Test1”
1>d:\work\win32project\testeachotherclude\testeachotherclude\testeachotherclude.cpp(15): error C2660: “Test2::className”: 函数不接受 1 个参数
1>d:\work\win32project\testeachotherclude\testeachotherclude\testeachotherclude.cpp(16): error C2039: “test1”: 不是“Test2”的成员
1> d:\work\win32project\testeachotherclude\testeachotherclude\test2.h(7) : 参见“Test2”的声明
1>d:\work\win32project\testeachotherclude\testeachotherclude\testeachotherclude.cpp(16): error C2227: “->refMe”的左边必须指向类/结构/联合/泛型类型
上传Test方便大家看:
main.cpp
#include "stdafx.h"#include "Test1.h"#include "Test2.h"int _tmain(int argc, _TCHAR* argv[]){Test1* t1=new Test1();Test2* t2=new Test2();t1->className(t2);t1->test2->refMe();t2->className(t1);t2->test1->refMe();return 0;}
再来看Test1的
Test1.h
#ifndef Test1_H#define Test1_H#include "Test2.h"class Test1{public:Test2* test2;void Test1::className(Test2* test2);void refMe();};#endif;
Test1.cpp
#include "Test2.h"void Test1::className(Test2* test2){this->test2=test2;std::cout<<"Test1 ";}void Test1::refMe(){std::cout<<"refMe Test1"<<std::endl;}
Test2.h
#ifndef Test2_H#define Test2_H#include "Test1.h"class Test2{public:Test1* test1;void className(Test1* test1);void refMe();};#endif
Test2.cpp
#include "StdAfx.h"#include "Test2.h"#include <iostream>void Test2::className(Test1* test1){this->test1=test1;std::cout<<"Test2 ";}void Test2::refMe(){std::cout<<"refMe Test2"<<std::endl;}
然后运行就报上面的一对错误了...
仔细看看发现两个头文件都彼此包含了,就是这个问题啦...那我们怎么解决了,上传我的代码,直接看这样更容易理解 main.cpp不变
Test1.h
#ifndef Test1_H#define Test1_H//#include "Test2.h" //用下面的方式替代class Test2;//注意:只是告诉编译器,需要这个类,其他功能结构等都没class Test1{public:Test2* test2;void Test1::className(Test2* test2);void refMe();};#endif;
Test1.cpp
#include "StdAfx.h"#include "Test1.h"#include <iostream>#include "Test2.h" //注意:这里才是真正的包含void Test1::className(Test2* test2){this->test2=test2;std::cout<<"Test1 ";}void Test1::refMe(){std::cout<<"refMe Test1"<<std::endl;}
Tes2的我就不贴了,一样的道理,编译运行ok ....
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认int 错误的解决方法
- 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int---->解决方法
- 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int---->解决方法 .
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 错误的解决方法
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int"错误的解决方法
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- afxwin1.inl(1014) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- ”error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int“ 解决办法
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 【MFC BUG】error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int"错误解决办
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- vs2008编译遇到error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 同事wxz的建议
- ORACLE 11g出现TNS: 协议适配器错误解决方法
- [Oracle] 函数用法集合
- [Cocoa]深入浅出 Cocoa 之 Core Data(1)- 框架详解
- “小智特惠” Android版已经登录各大电子市场,欢迎试用
- 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int---->解决方法
- Android4.1.1引起Cannot draw recycled bitmaps
- html5_canvas属性方法(下)
- 通过日志监控并收集 Java 应用程序性能数据
- 关于protobuff的一些理解
- 韩顺平_轻松搞定网页设计(html+css+javascript)_第25讲_js系统函数_js函数调用方式_学习笔记_源代码图解_PPT文档整理
- shell学习记录---5
- oracle to_timestamp
- 队列