1

A bit stupified by why the following complies just fine:

template<typename T> struct Foo { template<int i> struct Bar { typedef int BarSizeType; }; }; template<typename T, int i> void do_something(typename Foo<T>::Bar<i>::BarSizeType arg) { // ... } 

But this doesn't:

template<typename T, typename T2> struct Foo { template<int i> struct Bar { typedef int BarSizeType; }; }; template<typename T, int i> void do_something(typename Foo<T, T>::Bar<i>::BarSizeType arg) { // ... } 

The compilation errors are:

error C2143: syntax error : missing ')' before '<'
error C2143: syntax error : missing ';' before '<'
error C2988: unrecognizable template declaration/definition
error C2059: syntax error : '<'
error C2039: 'BarSizeType' : is not a member of '`global namespace''
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)

Any way I can make this compile, without making drastic changes to the code? I'm using vs2012 compiler.

1 Answer 1

4

It's a bug in MSVC; both are incorrect. You need to write template:

void do_something(typename Foo<T>::template Bar<i>::BarSizeType arg) { ^ here void do_something(typename Foo<T, T>::template Bar<i>::BarSizeType arg) { ^ and here 

For more information, see Where and why do I have to put the "template" and "typename" keywords?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.