So this a fairly easy assignment that we got from our teacher, but the thing that bugs me here is that I can't seem to get the overloading right. The assignment says:
int main()
{
cMoney papers(6, 50), coffee(5, 70), sugar(1), sugar1(sugar);
std::cout << "Total: " << papers + coffee + sugar1 << std::endl;
}
The portion of the code that I made so far is:
class cMoney{
private:
double mIznos;
public:
cMoney();
cMoney(double a);
cMoney(cMoney&);
cMoney& operator+=(const cMoney& paper);
~cMoney();
};
cMoney::cMoney(double a){
mIznos=a;
}
cMoney::cMoney(cMoney& number){
mIznos=number.mIznos;
}
cMoney& cMoney::operator+=(const cMoney& paper){
cMoney temp;
temp.mIznos=paper.mIznos;
return temp;
}
cMoney::~cMoney(){
std::cout<<"Destructor for:"<<mIznos<<std::endl;
}
int main(){
cMoney paper(6.50),coffee(5.70),sugar(1),sugar1(sugar);
return 0;
}
The problem is that I tried to make the overloading but I can't seem to figure out how to make papers + coffee + sugar1
. If it was papers=coffee+sugar or something similar OK. Just for the record; I just started learning C++ so please be gentle. :D