Forward declaration of a template class nested in a template class

You can redirect the declaration of the inner class of the template inside the normal class and use a specific type like any other formatted declared type.

class Outer { template <int N> class Inner; typedef Inner<0> Inner0; Inner0* f(); }; template<int N> class Outer::Inner {}; 

Now, if Outer itself is a template class, is there a way to save an Inner declaration outside of an Outer declaration? Sort of:

 template<typename T> class Outer { template <int N> class Inner; typedef Inner<0> Inner0; Inner0* f(); }; template<typename T, int N> //This won't work class Outer<T>::Inner {}; 

Is there any correct syntax for declaring an Outer with the parameters of the correct template?

+5
source share
1 answer

Try to execute

 template<typename T> template <int N> class Outer<T>::Inner {}; 

According to C ++ Standard (14.5.2 Member templates)

1 A template can be declared in a class or class template; such a template is called a member template. A member template can be defined inside or outside the definition of its class or the definition of a class template. a template of a class template member that is defined outside its class template definition should be specified using the template parameters of the class template, followed by the template parameters of the member template.

+7
source

All Articles