I have a hierarchy of base class and derived class. Base class has one virtual function which is overridden by derived class.
class Base
{
public:
~Base();
virtual void other_functionality() = 0;
};
class Derived : public Base
{
public:
~Derived ();
void other_functionality() {//some code};
};
Now if i do like this:
int main()
{
Base * P = new Derived ();
delete p;
return 0;
}
It gives error:
deleting object of polymorphic class type which has non-virtual destructor.
But with unique_ptr it passes without warning.
int main()
{
std::unique_ptr<Base> p;
p.reset(new Derived ());
return 0;
}
I know if I use virtual destructor. Warning with naked pointer will be solved. But question remains - why absence of virtual destructor shows problem with naked pointer and not with unique_ptr.