-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathenum.cpp
51 lines (36 loc) · 885 Bytes
/
enum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
enum class Color1 {
red,
blue,
green
};
enum struct Color2: char{
red= 100,
blue, // 101
green // 102
};
void useMe(Color2 color2){
switch(color2){
case Color2::red:
std::cout << "Color2::red" << '\n';
break;
case Color2::blue:
std::cout << "Color2::blue" << '\n';
break;
case Color2::green:
std::cout << "Color2::green" << '\n';
break;
}
}
int main(){
std::cout << '\n';
std::cout << "static_cast<int>(Color1::red): " << static_cast<int>(Color1::red) << '\n';
std::cout << "static_cast<int>(Color2::red): " << static_cast<int>(Color2::red) << '\n';
std::cout << '\n';
std::cout << "sizeof(Color1) = " << sizeof(Color1) << '\n';
std::cout << "sizeof(Color2) = " << sizeof(Color2) << '\n';
std::cout << '\n';
Color2 color2Red{Color2::red};
useMe(color2Red);
std::cout << '\n';
}