dimanche 29 novembre 2015

Inheriting a type declaration in the presence of templates

Is there a way to declare types in a base class template and re-use those definitions in the child class template?

For example, consider the following attempt:

template <typename T_>
struct A {
    using T=T_;
};

template <typename T_>
struct B: public A<T_> {
    T a;
};

The compiler complains that using the type T in the definition of B is illegal. It doesn't wait for instantiation to see that this type is inherited from A. So, is there a way to declare types in a base class template and re-use those definitions in the child class template?

Aucun commentaire:

Enregistrer un commentaire