I've recently started working the C++/CLI managed code, but I've always defined enums like so:

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

Until today, when I was hit with the error message:

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

As suggested in the message and on various Stack Overflow questions, changing my code to:

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

quickly fixed the problem.

However, I'm still unaware of the differences between the 2 different ways I now know to define enums. Could anybody help clarify for me? And also what makes "enum class" more suitable for managed code?

Thanks in advance,

Guy

有帮助吗?

解决方案

The difference between unmanaged enums and managed enums that makes managed enums more becoming for managed code is that managed enums are managed code and unmanaged enums are unmanaged code. Managed enums can be communicated by the managed code metadata. Unmanaged enums cannot, meaning they may not manifest as part of a managed class.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top