Cppreference声称,除其他事项外,您可以专注于
- member enumeration of a class template
由于没有提供示例,我试图猜测如何做到这一点。
我最终得到了以下结果:
template <typename T> struct A
{
enum E : int;
};
template <> enum A<int>::E : int {a,b,c};
Clang(带有 -std=c++17 -pedantic-errors
的 8.0.0)编译它。
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
也拒绝代码
error C3113: an 'enum' cannot be a template
我是否正确地特化了枚举?如果没有,现在我要这样做吗?
最佳答案
the standard中有例子([temp.expl.spec]/6) 表明你所拥有的是正确的。那里是:
template<> enum A<int>::E : int { eint }; // OK
似乎是 gcc 错误。
关于c++ - 我们可以专门化类模板的枚举(类型)成员吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56300432/