![](/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.