I'm a newbie to C++ and especially C++11, so since I've now got to use it, a few questions about 'enum' and 'enum class' came up:
Can I assign values after the enumeration has been declared?
enum MyEnum;
MyEnum::HELLO = 0;
MyEnum::WORLD = 1;
Can I assign values to a number? (ex.: Myenum::0 = 2)
enum MyEnum;
MyEnum::0 = 16;
MyEnum::1 = 24;
MyEnum::3 = 64;
How does enum class work when using a struct or class as the underlying type?
Would the entries in the enumeration be valid instances of the struct/class?
class Test {
private int v = 0;
Test(int v) {
this->v = v;
}
};
enum class MyEnum : Test {
Test0 = new Test(0),
Test1 = new Test(1),
};
I found these links when I searched for the topic:
- http://www.stroustrup.com/C++11FAQ.html#enum
- Do we really need "enum class" in C++11?
- C++11 enum class instantiation
Which, as you can see, left a few questions.