런타임에서 type 정보를 이용할 수 있따!!
#include <iostream>
using namespace std;
class GrandParent {};
class Parent : public GrandParent {};
class Child : public Parent {};
int main() {
GrandParent g;
Parent p;
Child c;
cout << typeid(g).name() << endl; // class GrandParent
cout << typeid(p).name() << endl; // class Parent
cout << typeid(c).name() << endl; // class Child
// c의 before가 g라면
if (typeid(c).before(typeid(g))) {
cout << typeid(g).name() << " is super class of " << typeid(c).name() << endl;
// class GrandParent is super class of class Child
}
}
typeid(me).before(typeid(you))
형태로 네가 나의 조상에 있는지 알 수 있다. 자기 자신은 return 0;