| | | | | |

Dynamic Cast - 1

  • Derived class may acquire method not defined in the base class
    1. Multiple inheritance gives the derived class a method from another base class
    2. New class method to handle added variables in derived class
  • Base class pointer cannot "know" about new derived class methods
  • dynamic_cast<T>(p)
    returns a pointer of type T with the same address value as p
  • dynamic_cast<T>(p) may be applied only in up- and down-cast situations in a given class hierarchy
  • Derivation Table for the B,B2 Hierarchy
        Base:D1 D2 D3 B2
    Derived
    D1x  
    D2x  
    D3 x 
    D4  x
    D5   xx

    This table shows the class parent/child relationships. From the table, we see the following is_a relationships, denoted by ":"

    D1:B
    D2:B
    D3:D1:B
    D4:D2:B
    D5:D3:D1:B
    D5:B2


| | Top of Page | 10. C++ Classes Part 4: Polymorphism and OO Programming - 11 of 18