Segfault with delete[] operator & virtually derived classes

Nathan Sidwell nathan@codesourcery.com
Mon Mar 7 17:11:00 GMT 2005


JP Mercury wrote:

> main() {
>   A *list = new B[10];      // Allocate 10x derived, store first in A *list
this won't work. new B[10] gets you an array of 10 B objects, you can't
expect that to look like an array of A objects.

you should use an array of pointers to object -- or some container
object.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



More information about the Gcc-help mailing list