Mail Archives: djgpp/1998/04/16/13:16:47
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 -