devxlogo

Class Types Used in Typeid Expressions Must Be Completely Defined

Class Types Used in Typeid Expressions Must Be Completely Defined

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();  }
See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist