error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

 1 #include<iostream>
 2 using namespace std;
 3 
 4 
 5 extern int i;
 6 extern float f(float a);
 7 float b;
 8 float f(float a){
 9     return a+1.0;
10 }
11 int i;
12 int h(int x)
13 {
14     return x*i;
15 }
16 
17 main()
18 {
19     b=1.0;
20     i=2;
21     f(b);
22     h(i);
23     cout<<f(b)<<":"<<h(i)<<endl;
24     system("pause");
25 }

 

这段代码源于《C++编程思想》一书的代码

错误详情: error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int    e:\imfcapplications\002_01\002_01\_01.cpp    18    1    002_01
原因:C中允许未声明的函数返回int类型,C++中不允许。同时,为了兼容早期的C语言,因为第一个版本的C中内置类型只有int(char,double,float,bool都是后来加入的),既然只有一种类型,那么不写就默认int.C99标准中要求,对于这种写法至少给出编译警告.不建议采用这种老的书写方式.

参考:http://blog.csdn.net/w343051232/article/details/8152097

 

posted @ 2014-12-14 21:59  L.Tag.OP  阅读(19851)  评论(0编辑  收藏  举报