Difference between enum and enum class?

I recently started working with C ++ / CLI managed code, but I always defined enums as follows:

enum FV_MODE { IDLE,DRAG,ADD_HITBOX,ADD_HURTBOX }; 

Until today, when I received the error message:

 cannot define an unmanaged enum 'FViewer::FV_MODE' inside managed 'FViewer' 1> use 'enum class' 

As stated in the post and on various issues, changing my code to:

 enum class FV_MODE { IDLE,DRAG,ADD_HITBOX,ADD_HURTBOX }; 

quickly fixed the problem.

However, I still don't know the differences between the two different ways that I now know to define enumerations. Can someone help clarify me? And also what makes the "enum class" more suitable for managed code?

Thanks in advance,

Guy

+6
source share
1 answer

The difference between unmanaged enumerations and managed enumerations, which makes managed enums more accessible to managed code, is that managed enums are managed by code and unmanaged enums are managed by unmanaged code. Managed enumerations can be transmitted by managed code metadata. Unmanaged enumerations cannot, that is, they may not appear as part of a managed class.

+4
source

Source: https://habr.com/ru/post/947457/


All Articles