[Tuxcpprogramming] Re: [LC++] NEWBIE: initializing arrays

Mark Phillips mark at austrics.com.au
Thu Jul 12 11:48:05 UTC 2001


Dan hursh wrote:

> On Thu, 12 Jul 2001, Mark Phillips wrote:
>
> Turn the array into a pointer and you are there.
>
> > I would do something like...
> >
> > class myclass {
> >   private:
> >     unsigned int const size;
>       int *myarray;  // like so

You _can_ do this, but I prefer
    int myarray[size];

If you have the instance specific
constant, you may as well use it
and thereby declare what myarray
is more precisely.

>       ~myclass(){delete [] myarray;}  // a must
>

True --- I forgot that bit.

> > of course, <vector> from the STL is a very useful alternative, as another
> > poster pointed out.
>
> I would use vector unless you really only want a static size array and
> then maybe only if I wanted to use it with C calls.

Why?  The vector class seems very useful, and well suited for
a range of uses.  What problems does it have?

Cheers,

Mark.





More information about the tuxCPProgramming mailing list