Skip to content

Instantly share code, notes, and snippets.

@phg1024
Created March 31, 2018 01:30
Show Gist options
  • Save phg1024/b509bc85291fd47468ebf4e8c8b43715 to your computer and use it in GitHub Desktop.
Save phg1024/b509bc85291fd47468ebf4e8c8b43715 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <typeinfo>
#include <stdexcept>
using namespace std;
class A {
public:
virtual void print() { cout << "A" << endl; }
};
class B : public A {
public:
virtual void print() { cout << "B" << endl; }
};
class C : public A {
public:
virtual void print() { cout << "C" << endl; }
};
class MyE : public exception {
};
int main() {
const A& b = B();
const A& c = C();
cout << typeid(b).name() << endl;
cout << typeid(c).name() << endl;
cout << typeid(MyE()).name() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment