-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-example-08.cpp
More file actions
58 lines (44 loc) · 880 Bytes
/
template-example-08.cpp
File metadata and controls
58 lines (44 loc) · 880 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
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by jaco.ryu on 2019-07-19.
//
#include <iostream>
using namespace std;
template <class T1, class T2>
class GClass {
T1 data1;
T2 data2;
public:
GClass();
void set(T1 a, T2 b);
void get(T1 &a, T2 &b);
};
template <class T1, class T2>
GClass<T1,T2>::GClass() {
data1 = 0;
data2 = 0;
}
template <class T1, class T2>
void GClass<T1, T2>::get(T1 &a, T2 &b) {
a = this->data1;
b = this->data2;
}
template <class T1, class T2>
void GClass<T1, T2>::set(T1 a, T2 b) {
this->data1 = a;
this->data2 = b;
}
int main() {
int a;
double b;
GClass<int, double> x;
x.set(2, 0.5);
x.get(a, b);
cout << "a=" << a << '\t' << "b=" << b << endl;
char c;
float d;
GClass<char, float> y;
y.set('x', 234.34);
y.get(c, d);
cout << "c=" << c << '\t' << "d=" << d << endl;
return 0;
}