-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (35 loc) · 865 Bytes
/
main.cpp
File metadata and controls
46 lines (35 loc) · 865 Bytes
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
#include <iostream>
/* In C++03 enums are not type-safe, which can lead to counter-intuitive behavior.
C++11 suppors strongly typed enums to avoid that.
*/
enum Animals {
Cat,
Dog,
Fish
};
enum Appliances {
Fridge,
Dishwasher,
Oven
};
enum class Buildings {
Cathedral,
Townhall,
LumberMill
};
enum class Beers {
Becks,
Heinecken,
Peroni
};
int main(int argc, char* argv[]) {
Animals a1 = Animals::Cat;
Appliances a2 = Appliances::Fridge;
Buildings b1 = Buildings::Townhall;
Beers b2 = Beers::Heinecken;
if (a1 == a2) { // this is true as enums in C++03 are just integers
std::cout << "Enums are not type-safe!" << std::endl;
}
// if (b1 == b2) { // this throws a compile time error
return EXIT_SUCCESS;
}