-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut35.cpp
More file actions
31 lines (29 loc) · 922 Bytes
/
Copy pathtut35.cpp
File metadata and controls
31 lines (29 loc) · 922 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
#include<bits/stdc++.h>
using namespace std;
// destuctor never takes an argument nor does return any value
int count =0;
class num{
public:
num(){
count++;
cout<<"this is the time when constructor is calledfor 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";
cout<<"creating two more objects"<<endl;
num n2,n3;
cout<<"exiting main block"<<endl;
}
cout<<"back to the main function"<<endl;
return 0;
}
// dont worry this program is correct and not wrong. its just that vs code thinks we might define a count inside our class so it gives us warnings