枚举类的c++typedef/类型替换
c++ typedef/type substitution for enumeration class
据我所知,目前不可能执行C++11enum class
的typedef
。我想知道在封装类之外引用变量enum
时,是否有其他方法可以缩短其名称的长度。这里有一个例子:
// I would like to do something along the lines of:
class SegmentActivityState;
using SegmentActivityType = SegmentActivityState::ActivityStateType;
// ...However, this results in the compile time error:
// 'SegmentActivityState' does not name a type.
// Enumeration class definition
class SegmentActivityState
{
public:
enum class ActivityStateType : Index
{
PreExecution = 0, /**< Pre-execution state. */
Execution = 1, /**< Execution state. */
PostExecution = 2 /**< Post-execution state. */
};
private:
ActivityStateType ActivityState;
/**< unique object identifier tag. */
public:
// ... Methods that work on the ActivityState
}
最重要的问题是名称的长度,我必须用它来指代SegmentActivityType
之外的enum
。例如,为了进行类型比较,我需要编写非常详细的SegmentActivity.getState() == SegmentActivityState::ActivityStateType::PreExecution
。我不想做的两件事是:
typedef
在SegmentActivityState
上- 移动
enum class
ActivityStateTypeoutside of the class
SegmentActivityState`定义
您的问题与枚举无关。你不能这样做,因为你试图访问一个未定义类的成员。无论成员是什么,这都不会起作用。
把typedef放在类定义之后,这样就完全可以了。
相关文章:
- 如果可推导类型上有替换,可变参数模板类型推导会使编译器崩溃
- C++类型别名,其中值被替换
- 为表示一个或多个操作的C++函数的int参数寻找类型安全的替换
- 为什么在 ctor 的参数列表中将成员"x"的类型替换为"decltype(x)"会破坏类模板参数推导?
- 如何替换给定类型中的模板参数
- 从"wcslen"替换到"strnlen_s"时,用"const char*"进行类型转换是正确的方法吗?
- 通过替换类型重写参数包
- 不能将模板参数替换为类型模板参数_Ty
- 匹配部分专用化以按类型替换元组元素
- C 模板继承.子类应用固定类型替换基类中的类型
- 我可以使用预处理器将一个类型声明替换为另一个类型声明吗?
- 在这种情况下,有没有办法用单个解决方案替换两个仅在类型上不同的相似函数?
- 使用类型名参数时,模板参数推导/替换失败
- 应替换现有类型,向其添加新类型
- 替换特定字母的函数不会以 void 返回类型运行
- 枚举类的c++typedef/类型替换
- 我们可以将所有"int"参数和返回类型替换为 DllImport 方法签名中的"IntPtr"吗?
- C++ 代码类型替换失败
- 将adt_proxy类型替换为值类型时出现Boost融合错误
- 使用默认类型替换c++函数引用模板错误