Operators, Inheritance, and Upcasting - 2
- Member Functions and Implicit Parameter
Box b; // declares variable of type Box
b.SetDimensions(10,20,30); // sets dimensions of b to 10, 20, 30
Member Operators
- Operator call syntax may not be modified
- Number of parameters may not be changed
- Implicit parameter is the first
I/O Operators
std::ostream& operator << (std::ostream& os, const T& t); // outputs t to os
std::istream& operator >> (std::istream& is, T& t); // inputs T object to t
First parameter is a reference to a stream object
Because the only type T
parameter is the second parameter, these operators cannot be effectively
overloaded as member functions