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

  1. #include <iostream.h>
  2.  
  3. class Base {
  4. // Do nothing (not a polymorphic class)
  5. };
  6.  
  7. class Derived : public Base {
  8. // Do nothing (not a polymorphic class)
  9. };
  10.  
  11. void main()
  12. {
  13.     Derived  MyDerived;
  14.     Derived* pMyDerived = &MyDerived;
  15.  
  16.     // Successful upcast
  17.     Base* pBaseTest = dynamic_cast<Base*>(pMyDerived);
  18.     cout << "pMyDerived ";
  19.     cout << (pBaseTest ? "is" : "is not");
  20.     cout << " a Base*.\n";
  21. }
  22.