Problem 1
Mark the following statements as true or false. a. In \(\mathrm{C}++,\) all operators can be overloaded for user-defined data types. b. In \(\mathrm{C}++,\) operators cannot be redefined for built-in types. c. The function that overloads an operator is called the operator function. d. \(\mathrm{C}++\) allows users to create their own operators. e. The precedence of an operator cannot be changed, but its associativity can be changed. f. Every instance of an overloaded function has the same number of parameters. g. It is not necessary to overload relational operators for classes that have only int member variables. h. The member function of a class template is a function template. i. When writing the definition of a friend function, the keyword friend must appear in the function heading. j. Templates provide the capability for software reuse. k. The function heading of the operator function to overload the preincrement operator \((++)\) and the post-increment operator \((++)\) is the same because both operators have the same symbols.
Problem 2
What is a friend function?
Problem 3
What is the difference between a friend function of a class and a member function of a class?
Problem 5
Suppose that the operator \(<<\) is to be overloaded for a user-defined class mystery. Why must \(<<\) be overloaded as a friend function?
Problem 6
Suppose that the binary operator \(+\) is overloaded as a member function for a class strange. How many parameters does the function operator+ have?
Problem 7
When should a class overload the assignment operator and define the copy constructor?
Problem 10
Find the error(s) in the following code: class mystery //Line 1 \\[ \\{ \\] bool operator<=(mystery) ; //Line 2 \(y\) bool mystery: : \(<=\) (mystery rightobj) //Line 3 \\[ \begin{array}{l} \\{ \\ \\} \end{array} \\]
Problem 11
Find the error(s) in the following code: class mystery //Line 1 \\{ bool operator<= (mystery, mystery); //Line 2 \\[ y \\]
Problem 12
Find the error(s) in the following code: class mystery //Line 1 \\{ friend operator+(mystery); //Line 2 //overload binary + . . . };
Problem 13
In a class, why do you include the function that overloads the stream insertion operator, \(<<,\) as a friend function?