我们可以专业化类模板的枚举(类型)成员吗?
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(带有-std=c++17 -pedantic-errors
的8.0.0(编译它。
gcc(带有-std=c++17 -pedantic-errors
的9.1(用
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
在gcc.godbolt.org上尝试一下
我是否正确地专注于枚举?如果没有,现在我要这样做?
标准中有示例([temp.expl.spec]/6(建议您拥有的正确。那里有:
template<> enum A<int>::E : int { eint }; // OK
似乎是GCC错误。
相关文章:
- 访问C++中的类型成员
- 具有 STL 向量类型成员的类的复制内存
- 重载具有 2 个相同数据类型成员的构造函数
- std::void_t 和嵌套的非类型成员
- 返回对常量结构(指针类型)成员的引用:明显的左值到右值转换
- 使用各种数据类型成员创建对象的简便方法
- 将类类型成员定义为公共和私有之间有什么区别?
- 结构类型成员的默认构造函数中的默认参数
- 如何传递模板模板非类型成员函数指针
- 文本类类型成员函数约束
- 给定仅包含布尔类型成员的结构的两个对象 s1 和 s2,只要 s1 的成员为 true,请检查 s2 的每个成员是否为真
- 如何在 c++ 中使用二进制文件输入/输出读取/写入结构的字符串类型成员
- C++:将模板参数的模板类型成员加为好友的语法正确吗
- C++静态结构类型成员初始化
- C++:作为引用或指针的基类型成员变量
- 左值引用类型成员的用户定义移动构造函数
- 具有指针类型成员的类在 MSVS2012@debug 下销毁时失败.程序错误或错误源
- CRTP -- 访问不完整的类型成员
- 为什么C++默认初始化不对非类类型成员进行零初始化
- 请求非类类型成员