In the sample:
#include
using namespace std;
class B
{
public:
virtual void pvf() = 0;
};
template
class D : public B
{
p
The problem is your erroneous assumption that there is anything common between D
and D
. Template instances are types, and two different instances are two different types, end of story. It only so happens that instances of the same template have formally similar code, but with specialization you can define any type you like. In short, every type that you define explicitly is entirely independent, and there is no commonality across specialized template instances, even if they happen to have the same name.
For example:
template struct Foo
{
T & r;
const T t;
void gobble(const T &);
Foo(T *);
};
template <> struct Foo
{
std::vector data;
int gobble() const;
Foo(bool, int, Foo &);
};
The types Foo
and Foo
have nothing to do with one another, and there is no reason why any part of one should have any use inside the other.
If you want to factor out common features, use private inheritance:
template struct D : private DImpl { /* ... */ }