CJCoding With Joseph
15free / daySign inCreate account
Back to Multiple Choice Quiz

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics

Non-Virtual Destructor Leak

C++ quiz · Question 37
mediumPolymorphism

This code has a subtle bug when delete base runs. What is the issue?

Code

1#include <iostream>
2using namespace std;
3 
4class Base {
5public:
6 ~Base() {
7 cout << "Base destroyed" << endl;
8 }
9};
10 
11class Derived : public Base {
12 int* data;
13public:
14 Derived() { data = new int[100]; }
15 ~Derived() {
16 delete[] data;
17 cout << "Derived destroyed" << endl;
18 }
19};
20 
21int main() {
22 Base* base = new Derived();
23 delete base;
24 return 0;
25}