I'm recently working on some legacy codes written in C++98.
I am trying to get them compiled by C++17 compiler. A whole lot of warnings popped out as I was doing that. However, almost all the warnings were easily resolved. Except for this one:
struct Counter { Counter(int v) : m_val(v) {} int m_val; }; struct AClass { static Counter SEQ; }; template<> Counter AClass::SEQ = 0; The C++17 compiler gave a warning "too many template headers for...(should be 0)" for the line template<> Counter AClass::SEQ = 0;. (https://godbolt.org/z/G845K3cvv)
But for C++98 compiler it was totally OK. (https://godbolt.org/z/xErje7T8o)
Now, in order to resolve the warning, I need a complete understanding as to what does the statement mean in the C++98 world.
My gut feeling is that it is a full template specialization. And the template argument is empty. So it is equivalent to Counter AClass::SEQ = 0; and template<> means nothing. (https://stackoverflow.com/a/4872816/1085251)
Can anyone tell me exactly what it means?
template<>is either a typo, or an artefact resulting from editing a templated type to produced non-templated type). You may wish to look at stackoverflow.com/questions/4872809/…inline static Counter SEQ = 0;in the class definition.