home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Using Visual C++ 4 (Special Edition)
/
Using_Visual_C_4_Special_Edition_QUE_1996.iso
/
ch18
/
before.cpp
next >
Wrap
C/C++ Source or Header
|
1995-09-12
|
825b
|
38 lines
#include <iostream.h>
#include <typeinfo.h>
// Define our classes
class Base {
// Do nothing
// Force polymorphism
virtual void Nothing() { }
};
class Middle : public Base {
// Do nothing
};
class Derived : public Middle {
// Do nothing
};
// Show before relationship
void ShowBefore(const type_info& info1,
const type_info& info2)
{
cout << info1.name();
cout << (info1.before(info2) ? " is " : " is not ");
cout << "before " << info2.name() << "\n";
}
void main()
{
// Show the relationships
ShowBefore(typeid(Base), typeid(Middle));
ShowBefore(typeid(Base), typeid(Derived));
ShowBefore(typeid(Middle), typeid(Base));
ShowBefore(typeid(Middle), typeid(Derived));
ShowBefore(typeid(Derived), typeid(Base));
ShowBefore(typeid(Derived), typeid(Middle));
}