Make Base
's destructor private, and then make Derived
a friend of Base
:
template
class Base {
private: ~Base() = default;
friend Derived;
};
class Derived : public Base {
};
This does not actually make doing
class AnotherDerived : public Base {
};
illegal, but any attempt to actually construct an AnotherDerived
will fail.