[C++/CLI] Inizialization of enum class members

  • Thread starter Thread starter marco_segurini
  • Start date Start date
M

marco_segurini

Hi,

I like to know why in a enum the inizializator has to be fully
qualified even if it belongs to the enumeration.

Many thanks.
Marco.

//--- code
#include "stdafx.h"

using namespace System;

enum class ENUM_ID_TIPO_NODO
{
TNP_MIN = 0x80,
TNP_1 = ENUM_ID_TIPO_NODO::TNP_MIN, // ok
//TNP_1 = TNP_MIN, // error C2065: undeclared identifier
TNP_2,
TNP_3,
TNP_4,
TNP_5,
TNP_MAX
};

int _tmain()
{
ENUM_ID_TIPO_NODO en = ENUM_ID_TIPO_NODO::TNP_MIN;

return 0;
}
 
marco_segurini said:
Hi,

I like to know why in a enum the inizializator has to be fully
qualified even if it belongs to the enumeration.

Many thanks.
Marco.

//--- code
#include "stdafx.h"

using namespace System;

enum class ENUM_ID_TIPO_NODO
{
TNP_MIN = 0x80,
TNP_1 = ENUM_ID_TIPO_NODO::TNP_MIN, // ok
//TNP_1 = TNP_MIN, // error C2065: undeclared identifier
TNP_2,
TNP_3,
TNP_4,
TNP_5,
TNP_MAX
};

int _tmain()
{
ENUM_ID_TIPO_NODO en = ENUM_ID_TIPO_NODO::TNP_MIN;

return 0;
}




The code converted to C++/CLI:


enum class ENUM_ID_TIPO_NODO
{
TNP_MIN = 0x80,
TNP_1 = ENUM_ID_TIPO_NODO::TNP_MIN,
TNP_2,
TNP_3,
TNP_4,
TNP_5,
TNP_MAX
};

int main()
{
ENUM_ID_TIPO_NODO en = ENUM_ID_TIPO_NODO::TNP_MIN;

return 0;
}



Regarding the qualification, I guess it follows the syntax of a class:


class SomeClass
{
public:
static const int x=7;
};

// ...


int x = SomeClass::x;
 
marco_segurini said:
I like to know why in a enum the inizializator has to be fully
qualified even if it belongs to the enumeration.

That's a compiler bug. I had to track this one down as I know I've seen it
before. After finding the bug that had this, it didn't appear to be fixing
the particular issue listed but another one. So, I've reactivated that bug.
It may or may not get fixed in Whidbey.

If you want to track the progress of this bug, please file a bug via the
MSDN product feedback center (link below).
 
Back
Top