1

I've been doing a lot of C# programming lately and now going back to C++ I am missing a few language features, though I am wondering if it would be possible to do something similar.

In C# elements of an enum are accessed using the name of the enum as a prefix, like this…

enum TypeA { one, two, three };
TypeA varA = TypeA.one;

In C++ that is not the case, the elements are accessed directly by its name, without prefix—which also leads to duplication problems, if enum elements have the same name.

I am wondering, however, if there's a way or trick to do the same thing in C++, to have code that looks somewhat like this…

typedef enum { one, two, three } TypeA;
TypeA varA = TypeA.one;

It would be really helpful for me to have the ability to really create enums that allow me to duplicate names and that are then accessed using the respective prefix.

Ideas, anyone?

Striding Dragon
  • 225
  • 1
  • 9
  • [Enum class](https://stackoverflow.com/questions/32953650/difference-between-enum-and-enum-class). – user202729 Mar 04 '18 at 06:35
  • Thanks for the info. Could have done without the downvote, though. – Striding Dragon Mar 04 '18 at 06:43
  • 1
    You know, duplicate -> no research effort -> downvote. That's exactly what you get when you hover over the downvote button - "This question does not show any research effort ..." --- Remember that downvote is not a punishment, it's an indication that the question is bad. – user202729 Mar 04 '18 at 06:45

1 Answers1

0

For those, who are interested, here is the solution.

enum class TypeA { one, two, three };
TypeA varA = TypeA::one;
Striding Dragon
  • 225
  • 1
  • 9