Creating a private inherited internal public template using the using directive

I am trying to use the using directive to cast a public access declaration of a derived class to an inner class template declared in the database. Code:

 template <typename T> class Base { public: template<typename U> struct Inner; }; template<typename T> class Derived: private Base<T> { public: using typename Base<T>::template Inner; // make it visible Inner<T>* ptr; // no need for typename here, non-qualified name }; int main() {} 

Neither g ++ nor clang ++ compiles this code, both complain about

error: expected unqualified identifier before the template

As far as I know, Inner is the dependent name of the template, so you should use ::template and typename when defining its name, since Base<T>::Inner is the dependent type. I tried all possible combinations with / without typename/template and no one compiled. Is there a way to use Inner in the public Derived section?

+6
source share
1 answer

Impossible. Usage-declarations, from [namespace.udecl]:

using typename opt id identifier nested-name;

But an unqualified identifier cannot be a class template.

Instead, you can create an alias:

 template<typename T> class Derived: private Base<T> { public: template <typename U> using Inner = typename Base<T>::template Inner<U>; Inner<T>* ptr; }; 
+10
source

Source: https://habr.com/ru/post/988047/


All Articles