0
I was trying to create a virtual destructor for a class, however, when trying to compile the code below in 'Debug' mode, Visual Studio 2017 stopped running the program, reported that an exception was released and showed the error message "wntdll.pdb not Loaded".
I tried in 'Release' mode, the exception is not released, but the program is terminated prematurely at the same point.
Below the code of the program:
#include <iostream>
class Base {
protected:
int* m_data;
public:
Base(int data) {
std::cout << "Base Constructor.\n";
m_data = new int(data);
}
~Base() {
std::cout << "Base Destructor.\n";
delete m_data;
}
};
class Derived : public Base {
protected:
double* m_moreData;
public:
Derived(int data, double moreData) : Base(data) {
std::cout << "Derived Constructor.\n";
m_moreData = new double(moreData);
}
virtual ~Derived() {
std::cout << "Derived Destructor.\n";
delete m_moreData;
}
};
int main() {
Base* b = new Derived(10, 25.0);
delete b;
std::cin.get();
return 0;
}
The output of the program in both 'Debug' and 'Release' mode is:
Base Constructor.
Derived Constructor.
Base Destructor.
And in 'Debug' mode when I click the continue button, Visual Studio informs that the exception has been released on the line delete b;
.
How do I fix it?