We reproduce the class Money here, in part:
```
class Money
{
public:
Money( ); Money(int theDollar, int theCents);
Money(int theDollars); Money(double amount);// other
public members int getCents( ) const; int getDollars( )
const;private: int dollars; int cents;// other private
members};Note that * is not overloaded in the class, but operator + is
overloaded using an operator function with the following declaration:
Money
const operator+(const Money& amt1, const Money& amt2)
```
The question is, given the declarations,
```
Money baseAmount(100, 60); // $100.60
Money fullAmount;
```
which of the following operations are legal? If so, why? If not, why not?
a)```
BaseAmount + 25;
```
B. ```
25 + BaseAmount;
```
C. ```
baseAmount = 2 * baseAmount;
```
D. ```
baseAmount+baseAmount.
Part a) The compiler notes the left hand argument for + is a Money object, and the
right hand object is an int. It looks for an operator overloading with a Money left
hand argument. It finds the overloading with two Money parameters. So it then looks
for a way to convert an int object to a Money object. It finds the Money(int)
constructor, which it uses. Then it has the argument-parameter type match necessary
to invoke the operator+(const Money&,const MoneyADD&) overloaded
operator.
Part b) is quite similar to a)
Part c) is illegal, not because we couldn’t overload operator*, but because we did not
do so.
Part d) is a straightforward call to
```
operator+(baseAmount,baseAmount)
```
You might also like to view...
The styles associated with the document are displayed in the ________ area of the Styles Pane
Fill in the blank(s) with correct word
This vector function returns the number of elements in a vector.
a. size b. num_elements c. elements d. length