In C++, is it possible to forward declare a class as inheriting from another class?

A forward declaration is only really useful for telling the compiler that a class with that name does exist and will be declared and defined elsewhere. You can’t use it in any case where the compiler needs contextual information about the class, nor is it of any use to the compiler to tell it only a little bit about the class. (Generally, you can only use the forward declaration when referring to that class without other context, e.g. as a parameter or return value.)

Thus, you can’t forward declare Bar in any scenario where you then use it to help declare Foo, and it flat-out doesn’t make sense to have a forward declaration that includes the base class — what does that tell you besides nothing?

Leave a Comment