0

This code runs on Visual Studio 2013 but not on gcc 4.9.2:

template <typename T>
void foo(){
    T::value_type bar('a');

    cout << bar << endl;
}

int main() {
    foo<string>();

    return 0;
}

It seems that Visual Studio 2013 deduces type to allow me to implement types defined in template arguments whereas gcc 4.9.2 does not.

Is there a workaround for this that would allow this behavior in gcc?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288

1 Answers1

2

You need to tell the compiler that T::value_type names a type so that it knows how to parse the declaration.

typename T::value_type bar('a');

See this question for more details on where and why you need to do this.

Community
  • 1
  • 1
TartanLlama
  • 63,752
  • 13
  • 157
  • 193