Lets say I have a class which contains two enums.
enum NameType { Defined, Inherited };
enum ValueType { Defined, Inherited };
The numeration values are said to be "previously defined" in the second enum because they have the same names as the first enum. Is there a syntax that is concise and allows for these names?
I know in C# this isn't a problem, but in C++ it seems to be. I'm using C++11.
Since you're using C++11, I'd recommend using enum class.
enum class NameType { Defined, Inherited };
enum class ValueType { Defined, Inherited };
This fixes the scoping issue.
See http://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html for further discussion of enum class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With