根据优先选择的说法,gcc和msvc都已经完成了C++20 feature using enum的实现,这意味着我们用enum来声明能。
struct A {
enum e { /* ... */ };
};
struct S {
using enum A::e;
};但当我将其应用于模板时:
template <class T>
struct S {
using enum T::e;
};gcc 废品它与:
<source>:7:14: error: 'using enum' of dependent type 'typename T::e'
7 | using enum T::e;
| ^~~~
<source>:7:17: note: declared here
7 | using enum T::e;
| ^msvc还通过以下方式拒绝它:
<source>(7): error C2868: 'e': ill-formed using-declaration; expected a qualified-name
<source>(8): note: see reference to class template instantiation 'S<T>' being compiled我不知道为什么这不能工作,因为它似乎与非模板没有什么不同。
这是编译器错误还是格式错误?
发布于 2021-04-08 08:49:07
来自提案
详细说明说明者不应指定依赖类型,该类型应具有可达的枚举说明符。
在您的示例中,T::e是一个依赖类型。
https://stackoverflow.com/questions/67000270
复制相似问题