为什么此模板代码在VS2010中有效,而在VS2012中无效
Why does this template code work in VS2010, but not in 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 版本对要求template
和typename
的要求越来越严格。你错过了一个template
,VS2012抱怨是对的。
相关文章:
- 欧拉项目#8答案是大以获得有效答案
- 调整大小后指向元素值的指针unordered_map有效?
- 为什么是0;C++中的有效语句
- 最高有效数字侧的第N位
- GCC对可能有效的代码抛出init list生存期警告
- 有效地使用std::unordered_map来插入或增加键的值
- c++中O(n^(1/3))中一个数的除数的有效计数
- 使用无符号字符数组有效存储内存
- 自定义先决条件对移动分配运算符有效吗
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- 有哪些有效的方法可以消除一组 100 万个字符串>重复数据?
- 为什么这种直接初始化有效?(C++17)
- 递归函数有效,但无法记忆
- 在C++中初始化向量映射的最有效方法
- 如果变量名称不跟在 char* 后面,const char* 是否有效?
- 钳制迭代器是否有效
- 如何有效地在 std::vector 中插入一对?
- C++模板 t 不是有效的模板类型
- 检查由括号、方括号和大括号组成的一组方括号是否有效?
- 为什么此模板代码在VS2010中有效,而在VS2012中无效