#include<iostream>
using namespace std;
class Money
{
public:
Money operator +(Money& amount1,Money& amount2);
void write();
Money(long doallars,int cents);
int get_write();
private:
long all_cents;
};
int main()
{
Money cost(1,50),tax(0,15),total;
total=cost+tax;
total.write();
return 0;
}
Money::Money(long dollars,int cents)
{
all_cents=100*dollars+cents;
}
Money operator +(Money& amount1,Money& amount2)
{
Money temp;
temp.get_write()=amount1.get_write()+amount2.get_write();
return temp;
}
void Money::write()
{
cout<<all_cents;
}
int Money::get_write()
{
return all_cents;
}
下面是错误信息
D:\Microsoft Visual Studio\MyProjects\试错题\lihui.cpp(7) : error C2804: binary 'operator +' has too many parameters
D:\Microsoft Visual Studio\MyProjects\试错题\lihui.cpp(20) : error C2512: 'Money' : no appropriate default constructor available
D:\Microsoft Visual Studio\MyProjects\试错题\lihui.cpp(21) : error C2676: binary '+' : 'class Money' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\Microsoft Visual Studio\MyProjects\试错题\lihui.cpp(33) : error C2512: 'Money' : no appropriate default constructor available
D:\Microsoft Visual Studio\MyProjects\试错题\lihui.cpp(35) : error C2106: '=' : left operand must be l-value
哪个高手能一下解决掉我在加30分