home *** CD-ROM | disk | FTP | other *** search
- #include <iostream.h>
-
- class Base {
- // Do nothing
- void virtual Nothing() { } // Now polymorphic
- };
-
- class Derived : public Base {
- // Do nothing (not a polymorphic class)
- };
-
- void main()
- {
- Derived MyDerived;
- Derived* pMyDerived = &MyDerived;
-
- // Successful upcast
- Base* pBaseTest = dynamic_cast<Base*>(pMyDerived);
- cout << "pMyDerived ";
- cout << (pBaseTest ? "is" : "is not");
- cout << " a Base*.\n";
-
- // Successful(??) downcast
- if (pBaseTest) {
- Derived* pDerivedTest =
- dynamic_cast<Derived*>(pBaseTest);
- cout << "pBaseTest ";
- cout << (pDerivedTest ? "is" : "is not");
- cout << " a Derived*.\n";
- }
- }
-