我有一个方法,它接受一个浮点指针和一个int指针,然后执行pow(the float, the int)
并返回值。我得到了一个很大的错误,我似乎无法理解它告诉我的错误。C++浮点指针int指针
#include <cmath>
#include <iostream>
using namespace std;
float method3(float *f, int *i); //initialize pointer method
float flt; //init variable
int nt; //init variable
int main() {
method3(*flt, *nt); //run method 3, which will do the same math, but with pointers instead of value or reference
cout << flt; //print it out
return 0;
}
float method3(float *f, int *i) { //method 3, get float and int by pointers
return pow(f, i); //f to power of i back to original flt variable
}
请让我知道我在做什么错了?
'* flt'和'* nt'没有任何意义。 “*”的参数必须是一个指针,而不是“float”或“int”。 – Barmar 2014-09-19 18:41:27
'void'返回类型并返回'return pow(f,i);'只是错误的!此外,我看不到任何理由为什么这些参数作为指针传递,而不是简单地按值。 – 2014-09-19 18:43:09
'return pow(* f,* i);'然后,如果你坚持这个奇怪的函数签名! – 2014-09-19 18:47:47