RTTI(run-time type identification) ,like exceptions ,depends on type information residing in the virtual function table. If you try to use RTTI on a class
that has no virtual functions, you will get unexpected results.
for example:
//C24RTTIWithoutPolymorphism.cpp
#include <cassert>
#include <typeinfo>
#include <iostream>
using namespace std;
class X {
int i;
public:
// ...
};
class Y : public X {
int j;
public:
// ...
};
int main() {
X* xp = new Y;
// the two below condition is true;
assert(typeid(*xp) == typeid(X));
assert(typeid(*xp) != typeid(Y));
cin.get();
}
So RTTI is intended for use only with polymorphic class. Without virtual function table, the typeid() will not work;