Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct A
  6. {
  7.     A()
  8.     {
  9.         cout << "A created" << endl;
  10.     }
  11. };
  12.  
  13. struct B : A
  14. {
  15.     B() {
  16.         cout << "B created" << endl;
  17.     }
  18.     B(A a) : B()
  19.     {
  20.         cout << "A became B" << endl;
  21.     }
  22. };
  23.  
  24. struct ClassDealer
  25. {
  26.     static void Greet(A* clas)
  27.     {
  28.         cout << "I am " << typeid(*clas).name() << endl; //выведет имя структуры
  29.     }
  30.     static void Greet(B clas)
  31.     {
  32.         cout << "I am " << typeid(clas).name() << endl; //выведет имя структуры
  33.     }
  34. };
  35.  
  36. int main()
  37. {
  38.     A a; B b;
  39.  
  40.     ClassDealer::Greet(&a);
  41.     ClassDealer::Greet(&b);
  42.     ClassDealer::Greet(a);
  43.     ClassDealer::Greet(b);
  44.  
  45.     system("pause > NUL");
  46.     return EXIT_SUCCESS;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement