Operator Overloading and Dynamic Binding Flashcards
What is the syntax for upcasting an operator?
derived obj; // Derived object function (obj); // Function call
void function(base & object) // Base class reference { cout << object[i]; // Reference to the derived }
What is the syntax for using “virtual” with operators?
The same syntax as with using dynamic binding with normal member functions:
virtual class_name & operator = (const class & operand_2);
How do you create a non-member operator with dynamic binding?
// Non-member operator as wrapper friend bool operator < (const operand_1, const operand_2);
// Virtual member helper function virtual bool compare(const operand_1);
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?
Only the base class would need the operator implemented and then the virtual member helper function would be inherited.
What is the issue with rvlaue operators?
Rvalue operators return by value and returning or passing by value TURNS OFF dynamic binding.
What are virtual helper member functions?
They are member functions used in dynamic binding within a hierarchy to implement the task of a non-member operator.