enum-int casting: operator or function

后端 未结 5 1768
走了就别回头了
走了就别回头了 2021-01-02 12:59

In the external code that I am using there is enum:

enum En {VALUE_A, VALUE_B, VALUE_C};

In another external code that I am using there ar

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-02 13:18

    You can not overload operators for enums. Or am I missing something? Well, you could create some sort of dummy classes, that would have an implicit constructor taking an int, and then have a cast operator to an enum (and vice versa).

    So, the only solution is to have functions. Also, I would make the overloads as Patrick suggests.

提交回复
热议问题