Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this template code work in VS2010, but not in VS2012?

I have inherited a project making heavy use of template meta programming, and am now in the process of upgrading from Visual Studio 2010 to 2012. Some of the template-code no longer works in 2012. I have distilled a minimal example:

template <typename T, int i>
class MyClass
{
private:
    typedef typename T::Nested<i> Found;
};

Gives this error message:

    source.cpp(5): error C2059: syntax error : '<'
    source.cpp(6) : see reference to class template instantiation 'MyClass<T,i>' being compiled
    source.cpp(5): error C2238: unexpected token(s) preceding ';'

Further down in MyClass, I can use T::Nested<i>, it is just the typedef that does not work.

This example compiles in 2010, but not in 2012. What is wrong with this code?

like image 276
knatten Avatar asked Oct 01 '12 13:10

knatten


1 Answers

Each VS version is more and more strict about requiring template and typename. You're missing a template, and VS2012 is right to complain.

like image 128
Puppy Avatar answered Nov 16 '22 18:11

Puppy