Advertisement
MaximCherchuk

Полиморфизм в чистом виде

Mar 3rd, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. using namespace std;
  5.  
  6. class Base {};
  7. class Derived : public Base {};
  8. class Poly_Base {virtual void Member(){}};
  9. class Poly_Derived : public Poly_Base {};
  10.  
  11. typedef int myInt;
  12.  
  13. int main() {
  14.     cout << std::boolalpha;
  15.     cout << "int vs myInt: ";
  16.     cout << (typeid(int) == typeid(myInt)) << endl;
  17.     cout << "Base vs Derived: ";
  18.     cout << (typeid(Base) == typeid(Derived)) << endl;
  19.  
  20.     // non-polymorphic object:
  21.     Base* pbase = new Derived();
  22.     cout << "Base vs *pbase: ";
  23.     cout << (typeid(Base) == typeid(*pbase)) << endl;
  24.  
  25.     // polymorphic object:
  26.     Poly_Base* ppolybase = new Poly_Derived;
  27.     cout << "Poly_Base vs *ppolybase: ";
  28.     cout << (typeid(Poly_Base) == typeid(*ppolybase)) << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement