[英]Can we specialize a enum (type) member of a class template?
Cppreference声称,除其他外,你可以专攻一个
- 成员枚举类模板
由于没有提供示例,我试图猜测如何做到这一点。
我最终得到了以下内容:
template <typename T> struct A
{
enum E : int;
};
template <> enum A<int>::E : int {a,b,c};
Clang(8.0.0 with -std=c++17 -pedantic-errors
)编译它。
GCC(9.1 with -std=c++17 -pedantic-errors
)拒绝代码
error: template specialization of 'enum A<int>::E' not allowed by ISO C++ [-Wpedantic]
MSVC(带有/std:c++latest
v19.20也拒绝了代码
error C3113: an 'enum' cannot be a template
我是否正确地专注于枚举? 如果没有,现在我这样做?
标准中有一些例子([temp.expl.spec] / 6)表明你所拥有的是正确的。 那个是:
template<> enum A<int>::E : int { eint }; // OK
好像是一个gcc bug。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.