为什么此模板代码在VS2010中有效,而在VS2012中无效



我继承了一个大量使用模板元编程的项目,现在正在从Visual Studio 2010升级到2012。某些模板代码在 2012 年不再有效。我提炼出了一个最小的例子:

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

给出以下错误消息:

    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 ';'

再往下MyClass,我可以使用T::Nested<i>,只是typedef不起作用。

此示例在 2010 年编译,但不在 2012 年编译。这段代码有什么问题?

每个 VS 版本对要求templatetypename的要求越来越严格。你错过了一个template,VS2012抱怨是对的。

相关内容

最新更新