How can I use C++ enum types like C# ?
consider following definition in c++ :
enum myEnum { A, B, C};
myEnum en = A;
Now I want write line #2 as following line like C# :
myEnum en = myEnum.A;
??
How can I use C++ enum types like C# ?
consider following definition in c++ :
enum myEnum { A, B, C};
myEnum en = A;
Now I want write line #2 as following line like C# :
myEnum en = myEnum.A;
??
What exactly is the question here? Your C# example will work as you have written it (although it doesn't match the .NET naming conventions...)
Well, different rules in C++. Closest you could get is this slight abomination:
namespace myEnum {
enum myEnum { A, B, C};
}
myEnum::myEnum en = myEnum::A;
C++0x introduces enum class
that does exactly what you want:
enum class myEnum { A, B, C };
myEnum en = myEnum::A;
In C, I would probably use good old prefixing:
enum myEnum { myEnum_A, myEnum_B, myEnum_C };
myEnum en = myEnum_A;
C++0x introduces enum class that does exactly what you want:
enum class myEnum { A, B, C }; myEnum en = myEnum::A;
In C, I would probably use good old prefixing:
enum myEnum { myEnum_A, myEnum_B, myEnum_C }; myEnum en = myEnum_A;