-
Notifications
You must be signed in to change notification settings - Fork 17
/
destructor.cpp
52 lines (44 loc) · 916 Bytes
/
destructor.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
//constructor
#include<iostream>
using namespace std;
int count=0;
class complex{
private:
int a,b;
public:
complex(){
count++;
cout<<"\n constructor msg: object number "<<count<<"created";
}
~complex(){
cout<<"\ndestructor msg: object number "<<count<<"destroyed";
count--;
}
};
void fun(){
complex obj;
}
int main(){
cout<<"\nInside the main block..";
complex c1;
{
cout<<"\ninside in block 1..";
complex c2,c3;
cout<<"\nleaving block";
}
cout<<"\n back inside the main block";
return 0;
}
output
------
Inside the main block..
constructor msg: object number 1created
inside in block 1..
constructor msg: object number 2created
constructor msg: object number 3created
leaving block
destructor msg: object number 3destroyed
destructor msg: object number 2destroyed
back inside the main block
destructor msg: object number 1destroyed
--------------------------------