Enums reference in C++

F

fabrice.gautier

Hi,

I found some Visual C++ that looked like this:

enum colors { red, blue, green };

void f(void)
{
colors C;

C = colors::red /* Is this valid ?? */
}


Is the last assigment a valid C++ syntax? It looks as if defining an
enum also define a namespace of the same name.
This code doesnt compile with gcc. Is it some MS only extension or is
that defined in some revision of the C++ language spec ?

Thanks

-- Fox
 
I

Ioannis Vranos

Hi,

I found some Visual C++ that looked like this:

enum colors { red, blue, green };

void f(void)
{
colors C;

C = colors::red /* Is this valid ?? */
}


Is the last assigment a valid C++ syntax? It looks as if defining an
enum also define a namespace of the same name.
This code doesnt compile with gcc. Is it some MS only extension or is
that defined in some revision of the C++ language spec ?


This looks like a managed enum of C++ "managed extensions" (.NET) and is not part of ISO C++.


With the upcoming C++/CLI and VS 2005, CLI types are provided with a separate syntax than
ISO C++ facilities, to reduce confusion and preserve semantics (now with managed
extensions is "on context" and is upon he programmer to know exactly what is going on).
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,588
Members
45,093
Latest member
Vinaykumarnevatia00

Latest Threads

Top