File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments