Operator Overloading and Dynamic Binding Flashcards

1
Q

What is the syntax for upcasting an operator?

A
derived obj;       // Derived object
function (obj);    // Function call
void function(base & object)   // Base class reference
{
    cout << object[i];  // Reference to the derived
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax for using “virtual” with operators?

A

The same syntax as with using dynamic binding with normal member functions:

virtual class_name & operator = (const class & operand_2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a non-member operator with dynamic binding?

A
// Non-member operator as wrapper
friend bool operator < (const operand_1,  const operand_2);
// Virtual member helper function
virtual bool compare(const operand_1);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you create a virtual member helper function for all classes that use a non-member operator in a hierarchy, which class(es) need the operator implemented?

A

Only the base class would need the operator implemented and then the virtual member helper function would be inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the issue with rvlaue operators?

A

Rvalue operators return by value and returning or passing by value TURNS OFF dynamic binding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are virtual helper member functions?

A

They are member functions used in dynamic binding within a hierarchy to implement the task of a non-member operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly