In the example below, the using declarations from the base class are only inherited by the derived class that is a full specialization of the base class. I was surprised by that at first. Is this because "members of partial specializations are not related to the members of the primary template"? Is that necessary or strongly motivated by some use-case I haven't considered?
Additionally, that would make me expect that the member functions should also be unrelated. If that's the case, why doesn't use of the override
keyword cause issues?
template <typename T, typename U>
class Base {
public:
virtual ~Base() = default;
using TPtr = const T*;
using UPtr = const U*;
virtual void TFunc(TPtr t);
virtual void UFunc(UPtr u);
};
template <typename T>
class PartiallySpecialized : Base<T, int> {
public:
// These aren't inherited.
using BaseT = Base<T, int>;
using typename BaseT::TPtr;
using typename BaseT::UPtr;
// These are inherited?
virtual void TFunc(TPtr t) override {}
virtual void UFunc(UPtr u) override {}
};
class FullySpecialized : Base<double, int> {
public:
virtual void TFunc(TPtr t) override {}
virtual void UFunc(UPtr u) override {}
};
int main() {
PartiallySpecialized<double> p;
FullySpecialized f;
}