Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninitialized enumerator default values

Suppose we have followin declaration

enum visibility
{
   On  = 0,
   Off = 1,
   maxVisibility
};

Is the guaranteed value of maxVisibility enumerator 2 in C++11/C++0x standard ?

like image 865
deimus Avatar asked Sep 18 '13 09:09

deimus


1 Answers

Yes, it is guaranteed.

§ 7.2.2

If the first enumerator has no initializer,the value of the corresponding constant is zero. An enumerator-definition without an initializer gives the enumerator the value obtained by increasing the value of the previous enumerator by one.

like image 171
billz Avatar answered Oct 16 '22 01:10

billz