The Quantum Physicist The Quantum Physicist - 4 years ago 79
C++ Question

Prototype of a class that inherits from a template class in virtual public mode

The prototype class of this:

template <typename T>
class MyClass

is simply:

template <typename T>
class MyClass;

But what's the prototype of this class:

template <typename T>
class MyDerivedClass : public virtual MyBaseClass<T>

If I just remove the
, I get an error:

expected '{' before ';' token

Is this even possible? I'm using gcc 6.2.1 on Debian Stretch.

Answer Source

The inheritance specifier is part of a class's definition, not its declaration.

You can of course still declare the class, just not its inheritance relationship:

template <typename T>
class MyDerivedClass;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download