打印

函数编译问题

[复制链接]
796|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
txcy|  楼主 | 2013-8-31 09:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
为啥如下程序编译不通过
#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;
}

相关帖子

沙发
无冕之王| | 2013-8-31 09:41 | 只看该作者
至少要main之前声明一下。

使用特权

评论回复
板凳
yybj| | 2013-8-31 09:43 | 只看该作者
#include <iostream>
#include <cmath>
using namespace std;

int f(int xxx); //这里加一个申明!

int main()
{
int yy;
double x;
x=sqrt(9);
cout << "你好啊" <<f(2) << "\n";
return 0;
}
int f(int xxx)
{
return xxx*100;
}

使用特权

评论回复
地板
xsgy123| | 2013-8-31 09:58 | 只看该作者
你这个只需要在你需要使用这个函数之前的任何位置进行一下申明就没问题了,只用申明一次就行

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

274

主题

2106

帖子

0

粉丝