When you use operator typeid, the class type of its argument must be completely defined. This means that a forward declaration of the argument’s base class is insufficient, as in this example:
class Base; //forward declaration of a base void func(Base *pb) { if (typeid(*pb) != typeid(Derived)) //trouble do_something(); }
In order to make this code work properly, the declarations of both Derived and Base have to be accessible from the scope of the typeid expression. You can make them accessible by #including their header file:
#include "Base.h" #include "Derived.h" void func(Base *pb) { if (typeid(*pb) != typeid(Derived)) //now fine do_something(); }