我一直試圖在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
功能,改變按引用傳遞似乎沒有任何工作。我必須錯過簡單而明顯的東西?
「effective_rate + 1」是什麼意思(在你的代碼中)?畢竟,'effective_rate'是_function_,而不是數字。 – jogojapan