【发布时间】:2021-03-30 23:06:32
【问题描述】:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int e=0;
int b=0;
cout<<"Enter Exponent";
cin>>e;
cout<<"Enter Base";
cin>>b;
pow(e, b);
cout<<"Power:"<<e;
return 0;
}
void pow(int e, int b)
{
int t=1;
while(b==t)
{
e=e*b;
t++;
}
}
这是我收到的错误:
ulaga.cpp|29|error: 'pow' was not declared in this scope
谁能解释为什么会出现这个错误?
【问题讨论】:
-
将
pow()的定义移到main()之上或在main()之前声明函数,以便main()知道pow()是什么。 -
这个问题怎么算“参数传递错误”?
-
你的函数
pow没有返回或输出参数,并且似乎没有副作用,所以任何体面的编译器都应该优化它......也许你想要e一个输出参数,然后声明pow(int&e, int b)...你不应该称它为“pow”,这表明它正在计算一种能力,它没有......