What's an enum class and why should I care?

前端 未结 4 1791
谎友^
谎友^ 2021-01-12 19:21

For one who has never written a line of C++11, and who has, at the moment, no opportunity to program in C++11, can you, in one short paragraph., tell me:

What is an

4条回答
  •  温柔的废话
    2021-01-12 20:01

    Personnally I have used it in a tcp based messaging protocol: many of the fields were enum values that I needed to encode inside one byte only, so as to respect the messaging interface..

    All my enums were simply defined this way:

    enum class EnumFieldA : unsigned char { eValProperty1, eValProperty2};
    enum class EnumFieldB : unsigned char { eValProperty1, eValProperty2, eValProperty3};
    enum class EnumFieldC : unsigned char { eValProperty1, eValProperty2, eValProperty3, eValProperty4};
    ...
    

    there are also plenty of thorough answers in this SO question.

提交回复
热议问题