This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Segfault with delete[] operator & virtually derived classes


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]