Sobes.tech
Junior — Senior

Determining program output with inheritance and destructors

livecode

Task condition

Specify what text will be printed to the console after executing the following program.

#include <iostream>

class BaseClass {
public:
    ~BaseClass() {
        std::cout << "Hello from ~BaseClass()" << std::endl;
    }
};

class DerivedClass : public BaseClass {
public:
    ~DerivedClass() {
        std::cout << "Hello from ~DerivedClass()" << std::endl;
    }
};

int main() {
    BaseClass* ptr = new DerivedClass();
    delete ptr;
    return 0;
}