This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Segfault with delete[] operator & virtually derived classes
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: JP Mercury <swirlee at stickist dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 07 Mar 2005 13:44:07 +0000
- Subject: Re: Segfault with delete[] operator & virtually derived classes
- Organization: Codesourcery LLC
- References: <20050305031551.M54068@stickist.com>
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