-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestructor2.cpp
59 lines (46 loc) · 991 Bytes
/
destructor2.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
// Creating a class
/*
Destructor
It is Just Opposite to Constructor with (~).
It is automatically Invoked when object goes out of scope.
It has No return Type
*/
class Employee
{
string name;
int id;
int salary;
public:
Employee()
{
cout << "This is a default constructor" << endl;
}
Employee(int id, int salary, string name)
{
this->name = name;
this->salary = salary;
this->id = id;
}
void get_data()
{
cout << "The name is : " << name << endl;
cout << "The Id is : " << id << endl;
cout << "The Salary is : " << salary << endl;
}
~Employee(){
cout<<"I'm a Destructor and now I'm called\n";
}
};
// Main Function -> Code Execution Starts here
int main()
{
// Creating Obj
// Class_name obj_name
Employee e1(12, 10000, "Yash");
e1.get_data();
Employee e2;
Employee e3;
return 0;
}