#include <iostream>
enum EnumDefault {A, B};
enum EnumChar : char {C, D};
enum EnumShort : short {E, F};
enum EnumInt : int {G, H};
enum EnumLongLong : long long {I, J};
enum class EnumClassDefault {A, B};
enum class EnumClassChar : char {C, D};
enum class EnumClassShort : short {E, F};
enum class EnumClassInt : int {G, H};
enum class EnumClassLongLong : long long {I, J};
int main()
{
std::cout << sizeof(EnumDefault ) << " " <<
sizeof(EnumChar ) << " " <<
sizeof(EnumShort ) << " " <<
sizeof(EnumInt ) << " " <<
sizeof(EnumLongLong ) << " " <<
sizeof(EnumClassDefault ) << " " <<
sizeof(EnumClassChar ) << " " <<
sizeof(EnumClassShort ) << " " <<
sizeof(EnumClassInt ) << " " <<
sizeof(EnumClassLongLong) << std::endl;
return 0;
}
// Output: 4 12 4 8 4 1 2 4 8
Reference: https://isocpp.org/wiki/faq/cpp11-language-types#enum-class
Monday, August 7, 2017
C++11: enum class: Underlying Type
You can specify the underlying type of an enum class. Here is an example:
Subscribe to:
Post Comments (Atom)
nixce post
ReplyDeleteBahaya Merokok