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.

alexyav
  • 97
  • 1
  • 5

1 Answers1

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?

Community
  • 1
  • 1
ecatmur
  • 152,476
  • 27
  • 293
  • 366