gpt4 book ai didi

c++ - 没有候选错误编译错误

转载 作者:行者123 更新时间:2023-11-28 00:02:28 25 4
gpt4 key购买 nike

我正在尝试编译我的应用程序,但它一直遇到“不匹配'operator<<'...目前尚不清楚程序的确切错误似乎是什么,因为他的对象配置正确我能看到。

#include <iostream>
#include <conio.h>
#include <cmath>
#include <stdexcept>

using namespace std;
class MortgageCalc
{
protected:
float term;
public:
void setData(float, float, float);
float setTerm ();
float monthly;
float total;
float interest;
float setLoan(void); //mutator
float setIntrest(void); //mutator
float setYears(void);
int years;
float loan;
};

void MortgageCalc::setData(float l, float i, float y)
{
loan = l;
interest = i;
years = y;
setTerm();
}

float MortgageCalc::setTerm()
{ //simple interest calculation with power calc to establish whole number translation
term = pow((1 + ((interest/100) / 12)), (12 * years));
return term;
}

float MortgageCalc::setLoan(void)
{ //returns loan amt to private member
return loan;
}

float MortgageCalc::setIntrest(void)
{ //returns interest amt to private member
return interest;
}

float MortgageCalc::setYears(void)
{ //returns years to private member
return years;
}

class mPayment : public MortgageCalc
{
public:
int monthly()
{
return ((loan * ((interest/100) / 12) * term ) / (term - 1));
}
};

class tPayment : public mPayment
{
public:
int total()
{
return (monthly() * (years * 12));

}
};

class iPayment : public tPayment
{
public:
int plusInterest()
{
return (total() - loan);
}
};

int main()
{
double loan(0), interest(0);
int years = 0;
MortgageCalc mort1;

cout << "Enter the total loan amount on your mortgage loan: $"; //established loan variable
cin >> loan;
cout << "Enter the interest rate (in whole #'s only): "; //establishes interest rate variable
cin >> interest;
cout << "Enter the length of the loan in years: "; //establishes term of payments
cin >> years;
mort1.setData(loan, interest, years);

mPayment m;
cout << "Monthly payment due is " << m.monthly() << "." << endl;

tPayment t;
cout << "Total payment will be " << t.total() << "." << endl;

iPayment i;
cout << "Total payment plus Interest will be " << i.plusInterest() << "." << endl;

return 0;
};

最佳答案

cout << "Total payment plus Interest will be " << i.plusInterest << "." << endl;

plusInterest 是类方法指针。不出所料,std::ostream 不知道如何处理类方法指针,并且正确地表达了强烈的反对意见,反对这样一个荒谬的提议,它知道如何处理一些奇怪的类的方法指针。

你可能打算写:

cout << "Total payment plus Interest will be " << i.plusInterest() << "." << endl;

现在,这是一个正确的函数调用,它返回一个 intstd::ostream 现在很高兴接受这个 int,并用它施展魔法。

关于c++ - 没有候选错误编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37801227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com