vtable on stack

Florian Weimer fw@deneb.enyo.de
Tue Feb 2 13:11:00 GMT 2010


* Frank Winter:

> I think, its not possible to make use of the vtable with objects
> living on the stack.

This is not true.  C++'s brand of polymorphism does not interact well
with copying (due to slicing).  Your examples stress this point.

Put differently, you want to create an object of a type which is not
known at compile-time.  This is not directly possible in C++.
Workarounds generally use the heap because unknown types have unknown
sizes, and objects of unknown size don't mix well with stack
allocation.



More information about the Gcc-help mailing list