How to use enums in C++

前端 未结 14 497
臣服心动
臣服心动 2020-12-04 04:30

Suppose we have an enum like the following:

enum Days {Saturday, Sunday, Tuesday, Wednesday, Thursday, Friday};

I want to crea

14条回答
  •  有刺的猬
    2020-12-04 05:09

    Enums in C++ are like integers masked by the names you give them, when you declare your enum-values (this is not a definition only a hint how it works).

    But there are two errors in your code:

    1. Spell enum all lower case
    2. You don't need the Days. before Saturday.
    3. If this enum is declared in a class, then use if (day == YourClass::Saturday){}

提交回复
热议问题