home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch18 / vrtbase3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-13  |  828 b   |  38 lines

  1. #include <iostream.h>
  2.  
  3. class Base {
  4. public:
  5.     // Do nothing
  6.     void BaseFunc() { cout << "In Base.\n"; }
  7.  
  8.     // Now polymorphic so we can use RTTI
  9.     virtual void Nothing() { }
  10. };
  11.  
  12. class Middle1 : virtual public Base {
  13. public:
  14.     // Do nothing (not a polymorphic class)
  15.     void Middle1Func() { cout << "In Middle1.\n"; }
  16. };
  17.  
  18. class Middle2 : virtual public Base {
  19. public:
  20.     // Do nothing (not a polymorphic class)
  21.     void Middle2Func() { cout << "In Middle2.\n"; }
  22. };
  23.  
  24. class Derived : public Middle1, public Middle2 {
  25. public:
  26.     // Do nothing (not a polymorphic class)
  27.     void DerivedFunc() { cout << "In Derived.\n"; }
  28. };
  29.  
  30. void main()
  31. {
  32.     Derived  MyDerived;
  33.     Base*    pBase = dynamic_cast<Base*>(&MyDerived);
  34.     pBase->BaseFunc();
  35.     Derived* pDerived = dynamic_cast<Derived*>(pBase);
  36.     pDerived->DerivedFunc();
  37. }
  38.