Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <typeinfo>
- using namespace std;
- class Base {};
- class Derived : public Base {};
- class Poly_Base {virtual void Member(){}};
- class Poly_Derived : public Poly_Base {};
- typedef int myInt;
- int main() {
- cout << std::boolalpha;
- cout << "int vs myInt: ";
- cout << (typeid(int) == typeid(myInt)) << endl;
- cout << "Base vs Derived: ";
- cout << (typeid(Base) == typeid(Derived)) << endl;
- // non-polymorphic object:
- Base* pbase = new Derived();
- cout << "Base vs *pbase: ";
- cout << (typeid(Base) == typeid(*pbase)) << endl;
- // polymorphic object:
- Poly_Base* ppolybase = new Poly_Derived;
- cout << "Poly_Base vs *ppolybase: ";
- cout << (typeid(Poly_Base) == typeid(*ppolybase)) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement