-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path59defaultpintemp.cpp
More file actions
34 lines (31 loc) · 833 Bytes
/
Copy path59defaultpintemp.cpp
File metadata and controls
34 lines (31 loc) · 833 Bytes
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
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
// DEFAULT PARAMETERS IN TEMPLATE
template <class T1 = int, class T2 = float, class T3 = char> // Here, we passed the value of custom datatype T in the template
class Happy
{
T1 datax;
T2 datay;
T3 dataz;
public:
Happy(T1 a, T2 b, T3 c)
{
datax = a;
datay = b;
dataz = c;
}
void display()
{
cout << "Data of class is : " << this->datax << ", " << this->datay << ", " << this->dataz << endl;
}
};
int main()
{
Happy<> obj(2, 6.5, 'l'); // to access the default values of template, keep the <> empty
obj.display();
Happy<char, char, int> OBJ('F', 'r', 99); // if you provide different parameters in object declaration, they will take over
OBJ.display();
return 0;
}