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

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;
}
 
I

Ioannis Vranos

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;
 
B

Brandon Bray [MSFT]

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top