[C++ tips] Enums

All

Intro

   I personally think we subtilize enums in all the languages. The sentence “Francisco, you can use a Enum here instead of int” comes to my mind.

C++

   One thing that I like about c++ enums implementation is that you can break the flow:

All examples are from here [1]. I hope I don’t go to hell to use such clever examples here:

// color may be red (value 0), yellow (value 1), green (value 20), or blue (value 21)

enum color

{

    red,

    yellow,

    green = 20,

    blue

};

    Blue is 21!! Like, breaking the flow!

Defect Reports

   By the way, I don’t know if you like to search about Defect Reports, it is very helpful actually.
Spending some time on it might save your time in the future actually.

Refs[1] https://en.cppreference.com/w/cpp/language/enum

[2] http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1638

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s