Programming/[C++]
[C++] Template(템플릿)
iD이드
2018. 3. 21. 16:33

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
|
#include <iostream>
#include <iomanip>
using namespace std;
template <typename T>
void change(T &a, T &b) {
int temp;
temp = a;
a = b;
b = temp;
}
void main() {
int a = 1, b = 2;
char c = 'A', d = 'B';
float e = 3.7f, f = 4.3f;
change(a, b);
cout << a << setw(10) << b << endl;
change(c, d);
cout << c << setw(10) << d << endl;
change(e, f);
cout << e << setw(10) << f << endl;
}
|
cs |