In article <39AD3400.72FDEA87@sattel.com>,
Bruce Edge <bedge@sattel.com> wrote:
Yes, I know in hindsight this was a bad design decision. Assuming that one can
control the memory layout of a C++ class is either arrogant or ignorant,
depending on one’s level of experience > 
Turns out, someone had made the base class destructor virtual. This is what
had caused the vtbl pointer to get added to the class.
A last philosophical question, and a chance to flaunt my C++ ignorance, why
would you want destructor to be virtual?
For heterogeneous collections and the like.
If you place an object in a collection of, say, Shapes and the collection
becomes responsible for managing the lifetime of the objects, it will
be important for a delete of the object to invoke the correct
destructor for the actual derived class.
Think in particular of a class that uses zoned allocation. The destructor
will have to put the memory back in the correct zone. Also any owned
fields will have to be released.
e.g.
class Shape {
public:
void draw() {
}
virtual ~Shape() {
}
}
class WidgetShape {
public:
PtWidget_t *widget;
WidgetShape() {
widget = PtCreateWidget(…);
}
…
virtual ~WidgetShape() {
PtDestroyWidget(widget);
}
}
If a collection of Shape deleted a WidgetShape, the Widget would stick
around if the destructor weren’t virtual, as Shape::~Shape would be
called instead of WidgetShape::~WidgetShape.
Steve Furr email: furr@qnx.com
QNX Software Systems, Ltd.