请教自定义函数编译不通过的问题,谢谢
为啥如下程序编译不通过
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int yy;
double x;
x=sqrt(9);
cout << "你好啊" <<f(2) << "\n";
return 0;
}
int f(int xxx)
{
return xxx*100;
}
改成下面形式,把函数f放在main前面就行了呢??
#include <iostream>
#include <cmath>
using namespace std;
int f(int xxx)
{
return xxx*100;
}
int main()
{
int yy;
double x;
x=sqrt(9);
cout << "你好啊" <<f(2) << "\n";
return 0;
}
[解决办法]
至少要mian之前声明一下。
[解决办法]
你这个只需要在你需要使用这个函数之前的任何位置进行一下申明就没问题了,只用申明一次就行
[解决办法]
写在一个头文件里,然后源文件包含头文件!不管多少函数,c++中都是要提前申明的