| | | | | |

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
    1. Operator call syntax may not be modified
    2. Number of parameters may not be changed
    3. 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

| | Top of Page | 9. C++ Classes Part 3: Inheritance - 13 of 16