#include<iostream>
class base
{
public:
virtual ~base(){std::cout << "base\n";}
};
class derived : public base
{
private:
~derived(){std::cout << "derived\n";} /* destructor is private */
};
int main()
{
base *pt= new derived;
delete pt;
}
The above program compiles and runs fine. How does the derived class destructor get invoked being private ?
base
promises the availability of the destructor andderived
should not break whatbase
promises. – Copter