: However, when the
cast-expression
of a
delete-expression
refers to an object of class type,
because the deallocation function actually called is looked up in the scope of
the class that is the dynamic type of the object,
if the destructor is virtual, the effect is the same
. For example,
struct B {
virtual ~B();
void operator delete(void*, std::size_t);
};
struct D : B {
void operator delete(void*);
};
void f() {
B* bp = new D;
delete bp; }
Here, storage for the non-array object of class
D
is deallocated by
D::operator delete(),
due to the virtual destructor
. —
end note