-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
47 lines (39 loc) · 1.37 KB
/
main.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
//---------------------------------------------------------------------------
// Демонстрация передачи перечисления в функцию.
//---------------------------------------------------------------------------
#include <iostream>
using namespace std;
// Scoped enumeration:
enum class Color { Red, Orange, Yellow, Blue, Indigo, Violet };
// Unscoped enumeration:
enum Flavor : unsigned short int { Vanilla, Chocolate, Strawberry, Mint };
void print(int usi) {
cout << "void print(int usi)" << endl;
switch (usi) {
case Vanilla: cout << "Vanilla" << endl; break;
case Chocolate: cout << "Chocolate" << endl; break;
case Strawberry: cout << "Strawberry" << endl; break;
case Mint: cout << "Mint" << endl; break;
}
}
/*
// При определении этой функции она возьмет на себя вызов функции:
// Flavor f = Mint;
// print(f);
void print(Flavor& f) {
cout << "void print(Flavor& f)" << endl;
switch (f) {
case Vanilla: cout << "Vanilla" << endl; break;
case Chocolate: cout << "Chocolate" << endl; break;
case Strawberry: cout << "Strawberry" << endl; break;
case Mint: cout << "Mint" << endl; break;
}
}
*/
int main(int argc, char** argv) {
Flavor f = Mint;
print(f);
// void print(int usi)
// Mint
return 0;
}