Modern C++ for Absolute Beginners by Slobodan Dmitrović

Modern C++ for Absolute Beginners by Slobodan Dmitrović

Author:Slobodan Dmitrović
Language: eng
Format: epub
ISBN: 9781484260470
Publisher: Apress


To declare a variable of enumeration type MyEnum we write:enum MyEnum

{

myfirstvalue,

mysecondvalue,

mythirdvalue

};

int main()

{

MyEnum myenum = myfirstvalue;

myenum = mysecondvalue; // we can change the value of our enum object

}

Each enumerator has a value of underlying type. We can change those:enum MyEnum

{

myfirstvalue = 10,

mysecondvalue,

mythirdvalue

};

These unscoped enums have their enumerators leak into an outside scope, the scope in which the enum type itself is defined. Old enums are best avoided. Prefer scoped enums to these old-school, unscoped enums. Scoped enums do not leak their enumerators into an outer scope and are not implicitly convertible to other types. To define a scoped enum, we write:enum class MyEnum

{

myfirstvalue,

mysecondvalue,

mythirdvalue

};



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.