Tech Off Post

Single Post Permalink

View Thread: Enum C# vs C++
  • User profile image
    cro

    Sven Groot said:
    cro said:
    *snip*

    That'd work. With some trickery you would be able to declare variables without using the ::Value bit too, like this:

    class MyEnum
    {
    public:
        enum Value
        {
            None,
            Value1,
            Value2
        };
    
        MyEnum(Value value) : _value(value) { }
    
        operator Value() const
        {
            return _value;
        }
    private:
        Value _value;
    };


    Then you could simply use it as:
    MyEnum x = MyEnum::Value1;


    You'd have to repeat that code for every enum though.

    Thanks !