int func();
对于带空参数表的函数,C和C++有很大的不同。在C语言中,声明 int func2(); 表示“一个可带任意参数(任意数目,任意类型)的函数”。这就妨碍了类型检查。而在C++语言中它就意味着“不带参数的函数”。
#include <stdio.h>
void fun();
int main()
{
fun(1, 1);
return 0;
}
void fun(int a, int b)
{
printf("%d\n", a+b);
}
编译通过 $ gcc -Wall test.c -o test $ ./test 2
$ mv test.c test.cpp $ g++ -Wall test.cpp -o test test.cpp: 在函数‘int main()'中: test.cpp:6:10: 错误:too many arguments to function ‘void fun()' fun(1, 1); ^ test.cpp:3:6: 附注:在此声明 void fun(); ^~~
int main(void)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有