-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuto-keyword.cpp
More file actions
82 lines (50 loc) · 1.46 KB
/
Auto-keyword.cpp
File metadata and controls
82 lines (50 loc) · 1.46 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
// Untitled.cpp
// Link: https://youtu.be/2vOPEuiGXVo
// Title: The "auto" keyword in C++
// Creator: The Cherno
//
class Device {};
class DeviceManager {
private:
unordered_map<string, vector <Device*>> m_Devices;
public:
const unordered_map<string, vector <Device*>>& GetDevices() const;
};
string GetName () {
return "Ciao";
}
int main() {
setlocale(LC_ALL, "italian");
auto a = 5;
auto aa = 5L;
auto aaa = 5.5f;
auto aaaa = "Ciao";
auto name = GetName();
string name2 = GetName();
int b = name.size();
vector <string> strings;
strings.push_back("Apple");
strings.push_back("Orange");
for (vector <string>::iterator it = strings.begin(); it != strings.end(); it++) {
cout << *it << endl; // è uguale a scirevere
}
for (auto it = strings.begin(); it != strings.end(); it++) {
cout << *it << endl;
}
using DeviceMap = unordered_map<string, vector <Device*>>; // è uguale a
typedef unordered_map<string, vector <Device*>> DeviceMap;
DeviceManager dm;
// const unordered_map<string, vector <Device*>> & devices = dm.GetDevices();
// è uguale a scrivere
// DeviceMap& devices = dm.GetDevices();
// è uguale a
const auto& devices = dm.GetDevices();
return 0;
}
// auto è comodo ma bisognerebbe evitarlo, a volte puo tornare utile e a volte
// siamo quasi costretti ad usarlo (nei tempaltes)