-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut35.cpp
More file actions
34 lines (28 loc) · 766 Bytes
/
Copy pathtut35.cpp
File metadata and controls
34 lines (28 loc) · 766 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
// program to show the use of destructor and what is it
#include<iostream>
using namespace std;
int count=0;
class num{
public:
num(){
count++;
cout<<"This is the time when constructor is called for object number"<<count<<endl;
}
~num(){
cout<<"This is the time when my destructor is called for object number"<<count<<endl;
count--;
}
};
int main(){
cout<<"We are inside our main function"<<endl;
cout<<"Creating first object n1"<<endl;
num n1;
{
cout<<"Entering this block"<<endl;
cout<<"Creating two more objects"<<endl;
num n2, n3;
cout<<"Exiting this block"<<endl;
}
cout<<"Back to main"<<endl;
return 0;
}