-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter_05.cpp
68 lines (59 loc) · 1.26 KB
/
chapter_05.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Created by vickllny on 2023/12/23.
// auto 3
//
#include "iostream"
#include "string"
#include "map"
using namespace std;
int func1(){
map<int, string> person;
person.insert(make_pair(1, "alice"));
person.insert(make_pair(2, "jack"));
person.insert(make_pair(3, "lucy"));
map<int, string>::iterator it = person.begin();
for(; it != person.end(); ++it){
cout << "key: " << it->first << " ,value: " << it->second << endl;
}
return 0;
}
class T1{
public:
static int get(){
return 110;
}
};
class T2 {
public:
static string get(){
return "this is auto.";
}
};
template <class T>
void func(void){
auto ret = T::get();
cout << "ret: " << ret << endl;
}
template <class T, typename P>
void func3(void){
P ret = T::get();
cout << "ret: " << ret << endl;
}
int func2(){
map<int, string> person;
person.insert(make_pair(1, "alice"));
person.insert(make_pair(2, "jack"));
person.insert(make_pair(3, "lucy"));
auto it = person.begin();
for(; it != person.end(); ++it){
cout << "key: " << it->first << " ,value: " << it->second << endl;
}
return 1;
}
int main(){
// func2();
// func<T1>();
// func<T2>();
func3<T1, int>();
func3<T2, string>();
}