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).

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

Overriding an operator does not change

A
  • Operator precendence
  • associativity
  • the meaning of how operator works on objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When operator function is implemented as a member function

A
  • leftmost operand: class object or reference to it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When operator function is implemented as a non-member function

A
  • leftmost operand: any type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

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