I came up with this question while reviewing another message in
this newsgroup. I've been away on Java for quite a bit and have
a question on deletions.
I think I already know the answer but I thought I would check
with the group to be sure.
Why does C++ not call delete for both classes when the pointer
is released even when what was allocated was the derived class?
It seems to make pointers even more dangerous than I remembered.
#include <iostream>
using namespace std;
class base
{
public:
~base() {cout << "base" << endl;}
};
class derived: public base
{
public:
~derived() {cout << "derived" << endl;}
};
int main()
{
base *r = new derived();
delete r;
}