7 - Operator overloading Flashcards
1
Q
constantness of a const member function
A
A const member function is a member function that guarantees it will not modify the object or call any non-const member functions (as they may modify the object).
2
Q
Overriding an operator does not change
A
- Operator precendence
- associativity
- the meaning of how operator works on objects
3
Q
Operator overloading
A
- must have at least one operand that is user-defined: prevents overloading operators for standard types
- must adhere to the syntax of the original operator: % cannot be redefined to use a single operand
- cannot be used to create new operator symbols
4
Q
When operator function is implemented as a member function
A
- leftmost operand: class object or reference to it
5
Q
When operator function is implemented as a non-member function
A
- leftmost operand: any type
6
Q
How to overload ++ and – operators
A
- both post and pre increment/decrement should be overloaded
- often overloaded to support iterators and smart pointers