Why do people use enums in C++ as constants while they can use const?

前端 未结 12 1462
梦毁少年i
梦毁少年i 2020-12-08 02:28

Why do people use enums in C++ as constants when they can use const?

12条回答
  •  渐次进展
    2020-12-08 03:02

    One reason is that const requires more typing:

    enum { Val1, Val2, Val3 };
    

    ...versus...

    const int Val1=0, Val2=1, Val3=2;
    

提交回复
热议问题