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  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
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