Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top