如何使用在同一类的基模板中的类中声明的枚举
How do I use an enum declared in a class in that same class's base's template
对不起,wordy/延长的问题,但我不知道该怎么说。
我有一堂课。此类扩展了一个模板的基类。我想将在派生类中声明的枚举用作模板参数之一。这不是从中的价值,即实际的枚举,尽管我怀疑这有所作为。如果我尝试这样做,我会得到一个未确定的标识符错误,例如在这个简化的示例中。
template<class Value>
class Base
{
public:
Value foo;
}
class Derived : public Base<Derived::Colors>
{
enum Colors
{
blue,
red,
}
}
我已经尝试环顾四周,发现枚举在班级中无法进行,所以我不知道该怎么办。似乎是一个很大的监督,使这样的用例不支持,所以有办法做到吗?在我的实际代码中,我宁愿将这个枚举保留在我的班级中,因为它与其功能密切相关。
因此,事实证明,至少在C 11中,不可能做到这一点。一个人需要做类似的事情:
template<class Value>
class Base
{
public:
Value foo;
}
// Does not compile
enum Derived::Colors;
class Derived : public Base<Derived::Colors>
{
enum Colors
{
blue,
red,
}
}
在将其添加为模板参数之前,要知道Colors
。但是,由于前进的宣言与枚举合作,这是不可能的。基本上,如果它们在班级内部声明,则标准明确地不允许在该课堂之外声明。
相关文章:
- 访问在 C++ 结构中声明的枚举变量
- 如何使用默认值将枚举声明为 extern
- 如何转发声明枚举?
- 如何将枚举类转发声明为模板化类的内部类?
- 枚举前向声明与头文件
- C++:如何在声明枚举类的模板类主体之外定义枚举类?
- C# 使用C++库中声明的枚举
- 函数-本地枚举声明和 ADL 的交互
- 正向声明的枚举,默认值以.h为单位
- 在类访问混淆中声明的枚举类型
- C++ 使用枚举声明:如何导入所有枚举项
- 在枚举声明中C++变量声明
- 枚举声明中的枚举器的类型
- 在C++11中分离枚举声明和定义
- 不透明和匿名枚举声明如何符合标准的要求?
- C++中的Typedef枚举声明
- 此枚举声明是否符合标准?
- 枚举声明错误
- 多个枚举声明
- 这个冒号在枚举声明中的作用