Ok, that's why I've never thought about this. I don't think I've ever used a base pointer to delete a derived object. Coding
is not something I normally do.
But since it is possible the designers of C++ should have made all destructors implicitly virtual since delete knows absolutely nothing about the type of object that it is deleting. Also this would not effect those situations where virtual was not needed but it would correct the problem that occurs when it is.
Seems like an oversight to me. But like I said - personally I try to avoid creating objects in this way. My normal method is this:
Why would you want to access a derived class's constructor from a base pointer?? Why would you use a base pointer to create a derived object?
B* obj=new B();
D* obj=new D();
Seems unecessarily complex and 'jiggy' to me.
If you wanted a Square object, why not just do:
class Square, public Object
Object *obj=new Square();
What are the benefits of:
Square *obj=new Square();
Object *obj=new Square()