forked from abhijithshaji17/cpp-mastery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20.cpp
More file actions
22 lines (22 loc) · 787 Bytes
/
Copy path20.cpp
File metadata and controls
22 lines (22 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Template 1 - display in Cpp with class template
#include<iostream>
using namespace std;
template<class T> //this is a class template
class num{
private: //type need not be specified
T a;
public: //type needs to be specified
num(T x){
a = x;
}
void display(){
cout<<a<<endl;
}
};
int main(){ //execution starts from the main func.
num<int>obj1(10); //num mein ek integer object made and called.
obj1.display(); //another func. called to display it.
num<float>obj2(1.1); //same things with another object 2.
obj2.display();
return 0;
}