[英]Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast) enum
I have copied the variable data from enum type which is declared outside the structure to the enum type variable which is written inside structure but it is throwing building error as Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast) 我已经将变量数据从在结构外部声明的枚举类型复制到在结构内部写入的枚举类型变量,但由于引发向枚举类型的转换需要显式强制转换(static_cast,C样式强制转换或函数-样式转换)
enum TGenObjType //sundar
{
TYPE_UNDEFINED
, TYPE_CAR
, TYPE_TRUCK
, TYPE_MOTORBIKE
, TYPE_BIKE
, TYPE_PEDESTRIAN
};
struct SGenObjData
{
enum TGenObjType recogType ; /* #RTAS: input */ /* Object type (vehicle, pedestrian, ...) */
enum TGenObjType commuType ; /* #RTAS: input */ /* Object type (vehicle, pedestrian, ...) */
};
ushort j(0);
for (ulong i = 0; i < gol.mData.size(); ++i)
{
if (gol.mData[i].isValid > 0)
{
if (gol.mData[i].id <= OBJ_MAX_ID)
{
objectList.objectIdx[size_t(gol.mData[i].id)][size_t(SRC_LIST1)] = ushort(j);
switch (gol.mData[i].recognized_shape)
{
case EO_SHAPE_CAR : objectList.objects[j].recogType = TYPE_CAR ; break;
case EO_SHAPE_TRUCK : objectList.objects[j].recogType = TYPE_TRUCK ; break;
case EO_SHAPE_MOTORBIKE : objectList.objects[j].recogType = TYPE_MOTORBIKE ; break;
case EO_SHAPE_BIKE : objectList.objects[j].recogType = TYPE_BIKE ; break;
case EO_SHAPE_PEDESTRIAN: objectList.objects[j].recogType = TYPE_PEDESTRIAN; break;
case EO_SHAPE_UNDEFINED :
default : myDataLst.objectList.objects[j].recogType = TYPE_UNDEFINED ;
}// throwing an error Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
can anyone tell me what went wrong? 谁能告诉我哪里出了问题?
A named enum
is a distinct type. 命名enum
是一种独特的类型。 it has an underlying type and a "weak" enum
allows implicit conversion to the underlying type. 它具有基础类型,“弱” enum
允许隐式转换为基础类型。 It does not support implicit conversion from the underlying type to the enum
. 它不支持从基础类型到enum
隐式转换。 An enum
declared with the same name as another enum
but in a different scopr is a distinct type of its own (this applies to all types). 与另一个enum
声明相同名称但在另一个scopr中声明的enum
是其自身的独特类型(这适用于所有类型)。 Since the enum
does not support implicitly conversion from the underlying type you cannot simply assign the value of one enum
to another, even if the enum
's and all of their members have identical names and values. 由于enum
不支持从基础类型隐式转换,因此即使enum
及其所有成员具有相同的名称和值,也不能简单地将一个enum
的值分配给另一个enum
。
enum Foo
{
Bar = 0
};
is not the same as 与...不同
struct Object
{
enum Foo
{
Bar = 0
};
};
Both Foo
and Object::Foo
are distinct types and C++ does not allow implicitly conversion between them. Foo
和Object::Foo
都是不同的类型,C ++不允许在它们之间进行隐式转换。
Object:Foo innerFoo = Bar; // Error Bar and Object::Bar are not the same
Object:Foo innerFoo = Onject::Bar; // OK! They are the same!
It sounds like the two enum
's are redundant so you need to decide which version of TGenObjType
you want to use and delete the other. 听起来这两个enum
是多余的,所以您需要确定要使用的TGenObjType
版本,并删除另一个版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.