forked from wadehuber/codeexamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvdestruct.cpp
More file actions
36 lines (28 loc) · 686 Bytes
/
Copy pathvdestruct.cpp
File metadata and controls
36 lines (28 loc) · 686 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
35
36
#include<iostream>
using namespace std;
class MyBase {
public:
MyBase() { cout << "MYBASE Constructor" << endl; }
virtual ~MyBase() { cout << "MYBASE Destructor" << endl; }
};
class MyDerrived : public MyBase {
private:
int * a;
public:
MyDerrived(int x=0) {
a = new int;
*a = x;
cout << "MYDERRIVED Constructor: " << *a << endl;
}
~MyDerrived() {
cout << "MYDERRIVED Destructor: " << *a << endl;
delete a;
a=nullptr;
}
};
int main () {
MyDerrived c1(1);
MyBase * c2 = new MyDerrived(2);
delete(c2);
return 0;
}