CSE2305 - Object-Oriented Software Engineering
Self Assesment Questions
For each question choose the single response which best answers the question, or which completes the statement most accurately.
Question 162: | Why is operator overloading sometimes desirable |
To change the precedence of inbuilt operators for user-defined classes |
To make user-defined classes act more like inbuilt classes (i.e. to make them more intuitive to use) |
To improve the performance of operations between inbuilt types |
All of the above |
None of the above |
Question 163: | Which is the correct syntax to define an overloaded assignment operator for assigning object of class Y to objects of class X |
void operator=(Y& to, const X& from); |
void operator=(X& to, const Y& from); |
void Y::operator=(const Y& from); |
void X::operator=(X& to, const Y& from); |
void X::operator=(const Y& from); |
Question 164: | Which of the following operators cannot be overloaded? |
. |
:: |
** |
?: |
All of the above cannot be overloaded. |
Question 165: | If a binary operator is overloaded as a member function, how many parameters will the member function require? |
None. Both operands are passed via the object. |
One, to pass the second operand. The first operand is the object itself. |
Two, to pass the first and second operands. |
Three, to pass the first and second operands, and the object on which they were called. |
It's a trick question - binary operators can't be overloaded at all. |
Question 166: | If a binary operator is overloaded as a non-member function, how many parameters will the member function require? |
None. Both operands are already known. |
One, to pass the first operand. The second operand will be a member of the first. |
Two, to pass the first and second operands. |
It's a trick question - binary operators can't be overloaded as global functions, only as member functions of a class. |
It's a trick question - binary operators can't be overloaded at all. |
Question 167: | Why is it necessary to be able to overload some operators by specifying a global function (rather than a member function)? |
Because member functions are inherited |
Because member functions are slower than global functions |
Because inbuilt types can't have member functions |
Because sometimes the order of arguments puts an unmodifiable class as the first operand |
Because some operators are commutative (the order of operands doesn't matter) so we have to use a global function which will accept operands in either order. |
Question 168: | You can't have two or more overloadings of the same operator in a single class because: |
...operator overloading is different from function overloading |
...all operators of a class take the same first argument type, so any call would be ambiguous |
...every operator name has to be unique in its original scope |
...operator look-up has to be done at compile time, but the compiler can't know what the run-time operands to an operator will be |
You can have two or more overloadings of the same operator in a single class, as long as their signatures are distinct. |
Question 169: | If both MyClass::operator+ and MyClass::operator= are overloaded, what is the effect on MyClass::operator+=? |
None. The three operators are completely independent. |
MyClass::operator+= will automatically be overloaded to call MyClass::operator+ and then MyClass::operator=. |
MyClass::operator+= will automatically be overloaded to call MyClass::operator= and then MyClass::operator+. |
MyClass::operator+= will automatically be made invalid, and the error message will suggest that the user use MyClass::operator+ and MyClass::operator= instead. |
None of the above. |
Question 170: | Why can we say that operator overloading is a form of polymorphism? |
Because overloaded operators can be declared virtual. |
Because overloaded operators mean that code like a+b can do different things depending on the type of the objects a and b. |
Because polymorphism is the technical name for operator overloading. |
Because overloaded operators have many (poly) shapes (morphus). |
We can't say that, because it's not true. |
Question 171: | What is "function overloading"? |
When a single function does more than one job in a program |
When a single function has more than one definition in a program |
When two or more functions have the same name and parameter types |
When two or more functions have the same name but different parameter types |
When two or more functions have different names but the same parameter types |
Question 172: | Why is function overloading useful? |
It conserves identifiers |
It allows us to give related functions a common (and logical) name |
It allows us to pass the same arguments to different functions |
It reduces the total number of functions, therefore improving program performance |
It increases the total number of functions, therefore improving program flexibility |
Question 173: | What is the "signature" of a function? |
The binary pattern it forms when converted to assembler |
A technical term for the unique name of the function |
A technical term for the unique combination of the name and parameter types of a function |
A technical term for the unique combination of the name, parameter types, and return type of a function |
None of the above |
Question 174: | How does the compiler work out which version of an overloaded function to call? |
It calls the first function it finds with the correct name |
It calls the "most recently defined" function |
It calls the fastest available function with the correct name |
It calls the function with the "unique closest" signature |
It calls the function with the "unique longest" signature |
Question 175: | How can a call to an overloaded function be ambiguous? |
Its name might be misspelled |
There might be two or more functions with the same name |
There might be two or more functions with equally appropriate signatures |
The function might have the right signature, but be inaccessible |
The function might be polymorphic |
Last updated: October 1, 2005