delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/16/13:16:47

From: Charles Terry <cterry AT plinet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Dynamic memory allocation
Date: Thu, 16 Apr 1998 09:48:52 -0700
Organization: All USENET -- http://www.Supernews.com
Lines: 47
Message-ID: <35363674.151@plinet.com>
References: <352EDA1E DOT 7B0C55AF AT teccart DOT qc DOT ca> <352F708A DOT 352E AT plinet DOT com> <6h50nq$oae$4 AT hyperion DOT triode DOT net DOT au>
NNTP-Posting-Host: 21833 AT 207 DOT 174 DOT 3 DOT 194
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

telford AT xenon DOT triode DOT net DOT au wrote:
> 
> In comp.os.msdos.djgpp Charles Terry <cterry AT plinet DOT com> wrote:
> > J-Réginald Louis wrote:
> > >
> > > My question is not about DJGPP itself, but a general C++ question.
> > > I'm writting a 3D engine. I have a class called 'Scene' holding a list
> > > of object to render.
> > > The list is consisting of an array of pointers to type 'Object'. Like
> > > this:
> > >
> > > So, what I'm asking is how can I append and remove objects in the list
> > > dynamicaly?
> 
> > Have you been to comp.lang.c++ ?
> 
> Oh yes, one other point. If you have allocated memory
> inside an object then you must declare a destructor for that
> object and a copy constructor and an operator =() function.
> 
> The copy constructor is required when constructing one
> object out of another like:
> 
> MyObj x;
> MyObj y = x;
> 
> The operator=() function is used for any other assignment
> from one object to another and has to clean up the old
> allocation before copying the new allocation. These things
> are usually mentioned in C++ text books but you have to know
> to look for them, otherwise you won't realise their importance.
> 
>         - Tel
> 
I'm no c++ guru so I don't know if its compiler dependant
but both the turbo c++ I've used and gcc generate a copy 
constructor for you if you havn't defined any other constructors.
Also a default destructor is generated.
As long as the class doesn't do any internal calls to
new or malloc and doesn't need to do any initialization
in the constuctor, I get by without defining any constuctors
or destructors.
This approach has worked for me within the scope I've been
exposed to, but I'd love to be informed as to C++ conventions it
might be stepping on.
Charles Terry

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019