enum-int casting: operator or function

后端 未结 5 1764
走了就别回头了
走了就别回头了 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:10

    While implicit casting is more convenient than translation functions it is also less obvious to see what's going on. An approach being both, convenient and obvious, might be to use your own class with overloaded cast operators. When casting a custom type into an enum or int it won't be easy to overlook some custom casting.

    If creating a class for this is not an option for whatever reason, I would go for the translation functions as readability during maintenance is more important than convenience when writing the code.

提交回复
热议问题