Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct A
- {
- A()
- {
- cout << "A created" << endl;
- }
- };
- struct B : A
- {
- B() {
- cout << "B created" << endl;
- }
- B(A a) : B()
- {
- cout << "A became B" << endl;
- }
- };
- struct ClassDealer
- {
- static void Greet(A* clas)
- {
- cout << "I am " << typeid(*clas).name() << endl; //выведет имя структуры
- }
- static void Greet(B clas)
- {
- cout << "I am " << typeid(clas).name() << endl; //выведет имя структуры
- }
- };
- int main()
- {
- A a; B b;
- ClassDealer::Greet(&a);
- ClassDealer::Greet(&b);
- ClassDealer::Greet(a);
- ClassDealer::Greet(b);
- system("pause > NUL");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement