The usage of anonymous enums

后端 未结 8 653
无人及你
无人及你 2020-11-29 19:40

What is the purpose of anonymous enum declarations such as:

enum { color = 1 };

Why not just declare int color = 1

8条回答
  •  时光取名叫无心
    2020-11-29 20:25

    That's a so-called enum trick for declaring a compile-time integer constant. It's advantage is it guarantees that no variable is instantiated and therefore there's no runtime overhead. Most compilers introduce no overhead with integer constants anyway.

提交回复
热议问题