TITLE: base class pointer deletion sometimes undefined (Newsgroups: comp.std.c++, 6 Nov 97) GREENBERG: mlg@scr.siemens.com (Michael Greenberg) >I believe the following is definitely incorrect. (not that I think it >should be). > > class foo { } ; > class bar : public foo { } ; > > ... > > foo* f = new bar; > delete f; CLAMAGE: stephen.clamage_nospam@eng.sun.com (Steve Clamage) The result of the code is formally undefined, and no diagnostic is required. You can correctly delete an object via a pointer to a base class only if the base class has a virtual destructor. In the specific example with empty classes, the code would probably run without a problem on most (if not all) implementations. You just can't depend on it.