Skip to content

Commit 6326a32

Browse files
committed
base class virtual destructor usage explanation ..
1 parent 3123a56 commit 6326a32

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Virtual Destructors: Destructors of base classes should be virtual
3+
* If base class (Shape)'s DTOr is not virtual, then destructor of the base class is only called
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
class Shape {
10+
public:
11+
virtual ~Shape() {
12+
cout << "Shape class DTOr ..\n";
13+
}
14+
};
15+
16+
class Circle : public Shape {
17+
public:
18+
~Circle() {
19+
cout << "Circle class DTOr ..\n";
20+
}
21+
};
22+
23+
24+
25+
int main() {
26+
27+
Shape* circle = new Circle();
28+
delete circle;
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)