Nested template class syntax error (MSVC)
c++, templates, visual-c++
Solution
THE PROBLEM/SOLUTION
You are required to use the keyword `template` in this context to tell the compiler that `Bar` is indeed a template, as in the below snippet:
template<typename T, typename R, typename... S>
typename Foo<R, S...>::template Bar<T> fooBar() { // <--- LINE 33
...
}
BUT WHY?
We are required to use the `template` keyword whenever a template name is a dependent template name, without it the compiler will treat `Bar` in `Foo<R, S...>::Bar` as a non-template, which doesn't make sense; and it errors.
Further reading:
- Where and why do I have to put the “template” and “typename” keywords?
Problem
I am using Visual Studio 2013 and having some issues with a function returning a nested template class inside a template outer class. I have made a minimal example, the real one involves a lot more code: ``` template<typename R, typename... S> class Foo { public: template<typename T> class Bar { }; }; template<typename T, typename R, typename... S> typename Foo<R, S...>::Bar<T> fooBar() { // <--- LINE 33 } ``` This yields a whole set of errors (mostly from subsequent code): - 33: error C2988: unrecognizable template declaration/definition - 33: error C2059: syntax error : '<' And it also affects subsequent code, tons of syntax error come for all the lines afterwards. Am I not seeing something or could this be an issue of Visual Studio?