Skip to content

Commit 2a53b07

Browse files
committed
Member function templates and Overloading template function
1 parent a43d3a9 commit 2a53b07

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Templates4.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ! Member function templates and Overloading template function
2+
#include<iostream>
3+
using namespace std;
4+
5+
template<class T>
6+
class Sumit{
7+
public:
8+
T data;
9+
Sumit(T a){
10+
data = a;
11+
}
12+
void display();
13+
};
14+
15+
// ! this function is within the class, i'll seprate them the use scpoeresolution operator
16+
template <class T>
17+
void Sumit<T> :: display(){
18+
cout << data<<endl;
19+
}
20+
21+
// ! Function overloading
22+
void func(int a){
23+
cout << "I'm first function() " << a << endl;
24+
}
25+
26+
template <class T>
27+
void func(T a){
28+
cout << "I'm template function() " << a << endl;
29+
}
30+
31+
int main(){
32+
// Sumit<int> s(5);
33+
// Sumit<float> k(7.5);
34+
// Sumit<string> sk("SuKa");
35+
// cout << s.data<<endl;
36+
// k.display();
37+
// sk.display();
38+
func(4); // * who is called actually two function name is same the func first called when the exact match takes the higest priority
39+
return 0;
40+
}

Templates4.exe

44.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)