Defining a static data element of a template class in a template class

I have a template template inside another class template. The inner class has a static data member. I'm struggling to give a definition. The following example works in clang 3.8, but not in gcc-7.1

template <typename T>
struct Out {
  template <typename U>
  struct In {
    static int var;
  };
};

template <typename T>
template <typename U>
int Out<T>::template In<U>::var;

gcc gives an error:

error: template definition of non-template ‘int Out<T>::In<U>::var
 int Out<T>::template In<U>::var;
                             ^~~

What should I do to make gcc happy?


Edit: I get rid of templatedoing this work:

template <typename T>
template <typename U>
int Out<T>::In<U>::var;

Which still leaves the question, is it allowed here template?

+4
source share
1 answer

This type of definition will be more common without templatebefore In. The keyword templateis not required here because it Out<T>::Inis a "member of the current specialization."

, , template , . [temp.names]/4. " " . [Temp.dep.type]/4.

, :: , , , ([temp. ]/5), , . [temp.names]/5 :

[. typename, template , ; , -> . , . - ]

0

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


All Articles