Answer the following statements true (T) or false (F)
1. It is impossible to get short-circuit behavior for overloaded operator && or operator ||
2. Consider this operator overloading for class Money, modified from Display 8.1 by omitting the const modifier on the return type:
```
Money operator+(const Money& amt1,const Money& amt2);
```
Is the following expression legal? If legal, what could it mean, and where does the information that is assigned go?
```
Money m1(17.99), m2(23.57) m3(15, 22);
(m1 + m2) = m3;
```
3. C++ allows overloading of the function application operator ( ). Explain.
4. A friend function has access only to the private members and member functions of the class (and all objects of that class) of which it is a friend.
5. A class can have friends that are functions as well as friend classes.
1. True
Invocations of overloaded operators are function calls. All the arguments of function calls are evaluated before the function is called, making short circuit evaluation impossible. It is better not to overload the && or || operators.
2. True
Though legal, this bit of code does not mean much. What actually happens is that C++ makes an anonymous Money object to hold the results of m1+m2. This object is assigned from m3, then discarded. The const, which we removed from the return type, would make this strange assignment illegal.
3. True
The function application operator, operator( ) can be overloaded just as any other operator that can be overloaded. The book does not say so here, but this operator must be a member of the class, and must not be static.
4. False
A friend function, like every other function, has access to any public members of any class, the class of which it is a friend included. Friendship gives the function access to all public and private members.
5. True
A friend function has access to all members of the class of which it is a friend. When a class A is a friend of class B, then every member of class A is a friend function of class B. This grants full access to class B’s members to all function members of class A.
You might also like to view...
What are the major disadvantages of focus groups and mailed surveys as compared to interviewing techniques such as “think aloud”?
What will be an ideal response?
Find the greatest common divisor of two integers
What will be an ideal response?
A table of contents is usually inserted on the last page of the document
Indicate whether the statement is true or false
What are the relative advantages and disadvantages of SSDs and HDDs?
What will be an ideal response?