在 2 天内,我一直在尝试调试这个 C++ 错误数小时,但无法弄清楚或在搜索中找到答案。谁能帮助我解决这个问题?
错误:
111:44: error: arithmetic on a pointer to the function type 'double (double, int)'
return (principal * (pow((effective_rate + 1), years_elapsed)));
~~~~~~~~~~~~~~ ^
相关代码:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
using std::ios;
using std::cin;
using std::cout;
using std::endl;
double effective_rate(double annual_rate, int num_times_compounded=0);
double balance(double annual_rate, double principal, double &years_elapsed, int num_times_compounded=0);
double annual_rate;
int num_times_compounded;
double principal;
double years_elapsed;
int main() {
//code to get inputs and do printouts
}
double effective_rate(double annual_rate, int num_times_compounded)
{
if (num_times_compounded > 0) {
return (pow((1 + (annual_rate/num_times_compounded)), num_times_compounded) - 1);
} else {
return (pow(e, annual_rate) - 1);
}
}
double balance(double annual_rate, double principal, double years_elapsed, int num_times_compounded)
{
if (num_times_compounded > 0) {
[**this is line 111:**] return (principal * (pow((effective_rate + 1), years_elapsed)));
} else {
return (principal * (pow( (effective_rate + 1), num_times_compounded) ) );
}
}
似乎第二个函数没有看到第一个effective_rate
函数,并且更改为通过引用传递似乎也不起作用。我一定遗漏了一些简单而明显的东西吗?