Why is enum class preferred over plain enum?

前端 未结 9 2439
灰色年华
灰色年华 2020-11-22 10:12

I heard a few people recommending to use enum classes in C++ because of their type safety.

But what does that really mean?

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 10:46

    1. do not implicitly convert to int
    2. can choose which type underlie
    3. ENUM namespace to avoid polluting happen
    4. Compared with normal class, can be declared forward, but do not have methods

提交回复
热议问题