Operator Overloading
Operator Overloading
1) Using friend operator function, following perfect set of operators may not be
overloaded.
a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d. None of these
a. iterator
b. allocator
c. constructor
d. operator
4) Which of the following is the perfect set of operators that can’t be overloaded in
CPP ?
a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
a. Zero
b. One
c. Two
d. Three
a. Only 2
b. Only 1, 3
c. Only 2 , 3
d. All 1 , 2, 3
a. < iomanipulator.h>
b. < stdiomanip.h>
c. < stdmanip.h>
d. < iomanip.h>
a. explicit_cast
b. static_cast
c. dynamic_cast
d. reinterpret_cast
10) Which of the following manipulator is used for the representing octal equivalent
of a given decimal number?
a. oct
b. setbase(8)
c. tobase(8)
d. both a and b
e. all a, b, c
11) When overloading unary operators using Friend function,it requires_____
argument/s.
a. Zero
b. One
c. Two
d. None of these.
Q2: The correct function name for overloading the addition (+) operator is:
operator_+.
operator:+.
operator+.
operator(+).
The . operator.
The -> operator.
The [ ] operator.
The & operator.
().
==.
+=.
[].
Q2: Which situation would require the operator to be overloaded as a global function?
The left most operand must be a class object (or a reference to a class object).
The left operand is an int1.
The operator returns a reference.
The overloaded operator is =.
Q3: An overloaded + operator takes a class object and a double as operands. For it to be
commutative (i.e., a + b and b + a both work):
Q1: Suppose you have a programmer-defined data type Data and want to overload the <<
operator to output your data type to the screen in the form cout << dataToPrint; and allow
cascaded function calls. The first line of the function definition would be:
Q1: Suppose the unary ! operator is an overloaded member function of class String. For a String
object s, which function call is generated by the compiler when it finds the expression !s?
y.operator+=( z ).
y = y + z.
y = y operator+= z.
y operator+=( y + z ).
Q3: Which of the following lines would be the prototype for an overloaded cast operator
function that converts an object of user-defined type Time into a double?
Time::operator_cast(double) const;.
Time::static_cast double() const;.
Time::operator double() const;.
d. Time::double() const;.
Be used to convert the arguments for overloaded operators to the types needed by
those overloaded operators.
Take exactly one argument.
Be used implicitly in series to match the needs of an overloaded operator.
Be applied implicitly.
Q: Assume that the function call operator() is overloaded for data type String in the usual sense
of selecting a substring from a larger string. For a String object string1 with the character string
"ABCDEFGHI", what string does string1( 4 , 2 ) return?
"CDEF".
"EF".
"CD".
"EFGHI".
Q1: The conventional way to distinguish between the overloaded preincrement and
postincrement operators (++) is: