【发布时间】:2014-11-14 10:21:08
【问题描述】:
我有一个接收浮点指针和整数指针的方法,然后执行pow(the float, the 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。 -
void返回类型并返回return pow(f, i);是完全错误的!我也看不出为什么这些参数作为指针传递,而不是简单地通过值传递。 -
return pow(*f, *i);那么,如果你坚持这个奇怪的函数签名! -
如果你的编译器没有向你抛出一堆警告,你需要结束警告级别或使用更好的编译器!我认为将警告级别设置为比舒适级别高一点是一种很好的做法,并且在清除所有警告之前不要运行任何东西。
-
@OP 别大喊大叫,耐心点!
标签: c++ pointers floating-point int cin