Skip to content

Commit e44e9a4

Browse files
committed
Give templates defaults value and use best, worst case
1 parent 4727fd9 commit e44e9a4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Templates2.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<iostream>
2+
using namespace std;
3+
template <class T1 = int, class T2 = float, class T3=string>
4+
class Sumit{
5+
public:
6+
T1 a;
7+
T2 b;
8+
T3 c;
9+
Sumit(T1 x, T2 y, T3 z){
10+
a = x;
11+
b = y;
12+
c = z;
13+
}
14+
void display(){
15+
cout << "The value of a: "<< this->a << endl;
16+
cout << "The value of b: " << this->b << endl;
17+
cout << "The value of c: " << this->c << endl;
18+
}
19+
};
20+
int main(){
21+
Sumit<> k(57, 7.5, "Sumit7");
22+
k.display();
23+
cout << endl;
24+
Sumit<float, string, string> s(5.7, "K", "S");
25+
s.display();
26+
return 0;
27+
}

Templates2.exe

49.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)