![](/img/trans.png)
[英]How to assign an enum value to a double variable defined by the user ?? C++
[英]How to assign const enum variable to normal enum variable using C++?
我有两个枚举,如下所示:
typedef enum {
NONE = 0,
test1,
test2
} TestType;
enum class type
{
zero = 0,
one,
two,
three
};
当我将一个枚举分配给另一个枚举时,如下所示:
const type f_eType;
TestType l_etestType = f_eType;
我收到以下错误:
“type”类型的值不能用于初始化“TestType”类型的实体
有人可以帮助我如何在不使用static_cast
的情况下解决此错误。
如果您不想使用static_cast
那么您必须自己定义转换行为:
TestType convert(type val) {
switch(val) {
case type::zero:
return NONE;
//...
}
}
TestType l_etestType = static_cast<TestType>(f_eType)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.