[英]Can we specialize a enum (type) member of a class template?
Cppreference claims that, among other things, you can specialize a Cppreference声称,除其他外,你可以专攻一个
- member enumeration of a class template
成员枚举类模板
Since no examples were provided, I attempted to guess how to do that. 由于没有提供示例,我试图猜测如何做到这一点。
I ended up with following: 我最终得到了以下内容:
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
) compiles it. Clang(8.0.0 with
-std=c++17 -pedantic-errors
)编译它。
GCC (9.1 with -std=c++17 -pedantic-errors
) rejects the code with GCC(9.1 with
-std=c++17 -pedantic-errors
)拒绝代码
error: template specialization of 'enum A<int>::E' not allowed by ISO C++ [-Wpedantic]
MSVC (v19.20 with /std:c++latest
also rejects the code with MSVC(带有
/std:c++latest
v19.20也拒绝了代码
error C3113: an 'enum' cannot be a template
Try it on gcc.godbolt.org 在gcc.godbolt.org上试试吧
Did I specialize the enum correctly? 我是否正确地专注于枚举? If not, now do I do that?
如果没有,现在我这样做?
There are examples in the standard ([temp.expl.spec]/6) that suggest what you have is correct. 标准中有一些例子([temp.expl.spec] / 6)表明你所拥有的是正确的。 The one there is:
那个是:
template<> enum A<int>::E : int { eint }; // OK
Seems like a gcc bug. 好像是一个gcc bug。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.