I read from “Inside The C++ Object Model” that the type_info object is often stored at the first slot of the virtual table. However, I iterated the members in the virtual table:
class Base {
public:
virtual void f() { cout << "Base::f" << endl; }
virtual void g() { cout << "Base::g" << endl; }
virtual void h() { cout << "Base::h" << endl; }
};
typedef void(*Fun)(void);
Base b;
(Fun)*((int*)*(int*)(&b)+0); // Base::f()
(Fun)*((int*)*(int*)(&b)+1); // Base::g()
(Fun)*((int*)*(int*)(&b)+2); // Base::h()
As you see from the last three lines, I can’t find type_info at all.
There is no cross-compiler way to get at the
type_infofrom the address of an object. Nor would you expect there to be; the way to get atype_infois using a specific C++ keyword:typeid.