-
The class Money has two data members: dollars and cents. A function that overloads operator+ that adds two Money values and returns a Money value representing their sum is to be written. If this function is declared in the Money class at (*) below, which of the declarations shown would be correct?
class Money { int dollars; int cents; public: Money(); Money(int d, int c); // (*) Declare an overloaded operator+ ... };
(1) Money operator+(const Money& m) const; (2) Money operator+(const Money& m1, const Money& m2); (3) friend Money operator+(const Money& m1, const Money& m2); (4) friend Money operator+(const Money& m1, const Money& m2) const;
- Any one of these would be correct
- Only (1)
- Only (2)
- Only (1) or (3)
- Only (2) or (3)
- Only (1) or (4)
- Only (2) or (4)