这似乎可以在 MSVC 中按预期编译甚至工作。但它是合法的 C++ 代码吗?它是否能保证执行此处所期望的操作(即将模板类型导出到结构体的同名用户)?
template <typename EnumType>
struct Enum
{
// There are two hard problems in CS: cache invalidation and naming things.
typedef EnumType EnumType;
};
我认为类型定义是不允许的。
14.6.1 本地声明的名称 (N4296)
6 模板参数不得在其范围内重新声明
(包括嵌套范围)。模板参数不得与
模板名称。 [ 例子:
template<class T, int i> class Y {
int T; // error: template-parameter redeclared
void f() {
char T; // error: template-parameter redeclared
}
};
template<class X> class X; // error: template-parameter redeclared
—结束示例]
The typedef EnumType EnumType
是将模板参数重新定义为 typedef-name。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)