Recently, the interviewer asked me the following question: "Derived classes allow inheritance from the base class, but all derived classes must implement a user-defined destructor. If the derived class does not define a user destructor definition, report a compilation error ." Any idea how to solve this problem?
We decided to solve this problem using a pure virtual destructor in the base class, but this does not solve the problem.
For the below code, I want the compiler to report an error since the derived class does not implement a user-defined destructor
class Base
{
public:
virtual ~Base() = 0;
};
Base::~Base()
{
cout << "Base destructor" << endl;
}
*
class Derived : public Base
{
};
int main()
{
Derived d;
}