Error message "wntdll.pdb not Loaded" when creating a virtual destructor

Asked

Viewed 97 times

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?

1 answer

0


Forget the question. I made a silly mistake. I declared the destructor of the derived class as virtual, when the correct one was the base class destructor:

class Base {
protected:  
        int* m_data;    
public:
    Base(int data) {
        std::cout << "Base Constructor.\n";
        m_data = new int(data);
    }
    virtual ~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);
    }
    ~Derived() {
        std::cout << "Derived Destructor.\n";
        delete m_moreData;
    }
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.