Mark the following statements as true or false. a. The function that overloads a
ID: 3821285 • Letter: M
Question
Mark the following statements as true or false.
a. The function that overloads an operator is called the operator function. (1)
b. In C++, all operators can be overloaded for user-defined data types. (2)
c. In C++, operators cannot be redefined for built-in types. (2)
d. C++ allows users to create their own operators. (2)
e. The precedence of an operator cannot be changed, but its associativity
can be changed. (2)
f. A friend function of a class is a nonmember function of the class, so it
cannot access the members of the class. (4)
g. When writing the definition of a friend function, the keyword
friend must appear in the function heading. (4)
h. In C++, all operators can be overloaded as member functions of a class. (5)
i. Every instance of an overloaded function has the same number of
parameters. (1, 2, 5, 6)
j. It is not necessary to overload relational operators for classes that have
only int member variables. (1, 5, 6)
k. The function heading of the operator function to overload the pre-
increment operator (++) and the post-increment operator (++) is the
same because both operators have the same symbols. (6)
l. Templates provide the capability for software reuse. (8)
m. The member function of a class template is a function template. (9)
Explanation / Answer
Hi, I have answered first four part with explanation.
Please repost others in separate post.
Please let me know in case of any issue in first four part.
a. The function that overloads an operator is called the operator function.
Ans: True
C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.
b. In C++, all operators can be overloaded for user-defined data types.
Ans: False
In C++, following operators can not be overloaded:
. (Member Access or Dot operator)
?: (Ternary or Conditional Operator )
:: (Scope Resolution Operator)
.* (Pointer-to-member Operator )
sizeof (Object size Operator)
typeid (Object type Operator)
c. In C++, operators cannot be redefined for built-in types.
Ans: True
You cannot redefine a built-in operator. Operator overloading is designed to allow you to extend the language, not to change it. At least one of the parameters of an overloaded operator must be a user defined type (class or enum type) or a reference to a user defined type.
d. C++ allows users to create their own operators.
Ans: False
No, unfortunately you cannot define new operators—you can only overload existing operators (with a few important exceptions, such as operator.)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.