-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtemplates.cpp
115 lines (115 loc) · 1.26 KB
/
templates.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using namespace std;
#include<iostream>
/*template<class T1,class T2>
void add(T1 a,T2 b)
{
//T1 c;
cout<<a<<b<<endl;
//cout<<c;
}
void add(float a,char b){
cout<<a<<b<<"Overloaded"<<endl;
}
int main()
{
//char a='a';
add(4,1.1);
add(6.1f,'a');
}
*/
//class templates
/*
template<class T>
class abc{
T a,b;
public:
abc(){
cin>>a>>b;
}
void print(){
cout<<a<<b<<endl;
}
};
int main()
{
abc <int> a;
abc <float> b;
a.print();
b.print();
return 0;
}
*/
//combination of 2 datatypes
/*
template<class T1,class T2>
class abc{
T1 a;
T2 b;
public:
abc(){
cin>>a>>b;
}
void print(){
cout<<a<<b<<endl;
}
};
int main()
{
abc <int,float> a;
abc <float,float> b;
a.print();
b.print();
return 0;
}
*/
//member function templates
/*
template<class T1,class T2>
class abc{
T1 a;
T2 b;
public:
abc(){
cin>>a>>b;
}
void print();
};
template<class T1,class T2>
void abc<T1,T2>::print()
{
cout<<a<<b<<endl;
}
int main()
{
abc <int,float> a;
abc <float,float> b;
a.print();
b.print();
return 0;
}
*/
//#template and static variables
template<class T1>
class abc{
T1 a;
public:
abc(){
cin>>a;
}
void print();
};
template<class T1>
void abc<T1>::print()
{
static int c=0;
cout<<c<<a<<endl;
}
int abc<T1>::c;
int main()
{
abc <int> a;
abc <float> b;
a.print();
b.print();
return 0;
}