Have this basic hierarchy:
// header
class Base
{
virtual void method() { }
virtual ~method() { }
};
class Subclass : Base
{
virtual void method() { }
virtual ~method() { }
};
I wish to subclass Base with two explicit variations (without having to provide two implementations of Subclass if possible), so it has been suggested to use explicit template instantiation:
// header
class Base
{
virtual void method() { }
virtual ~method() { }
};
class Base1 : public Base { };
class Base2 : public Base { };
template <typename T>
class Subclass : public T
{
virtual void method();
virtual ~method() { }
};
// cpp
template <typename T>
void Subclass<T>::method()
{
}
template class Subclass<Base1>;
template class Subclass<Base2>;
I'm getting this error:
there are no arguments to 'method' that depend on a template parameter, so a declaration of 'method' must be available
Is this the correct approach? I would clearly have to template Base in order to get this to compile, but with what?