我有两个枚举,如下所示:
typedef enum {
NONE = 0,
test1,
test2
} TestType;
enum class type
{
zero = 0,
one,
two,
three
};
当我将一个枚举分配给另一个枚举时,如下所示:
const type f_eType;
TestType l_etestType = f_eType;
我收到以下错误:
“类型”类型的值不能用于初始化“ TestType”类型的实体
有人可以在不使用static_cast
的情况下帮助我如何解决此错误。
答案 0 :(得分:1)
如果您不想使用static_cast
,则必须自己定义转换行为:
TestType convert(type val) {
switch(val) {
case type::zero:
return NONE;
//...
}
}
答案 1 :(得分:-1)
TestType l_etestType = static_cast<TestType>(f_eType)