"ikl" <> wrote in message
news:nHPcc.30086$...
> When creating a list of objects of the same class, what should be
concerned
> to decide if using "new" or not?
You should almost never use new. If you need dynamic allocation of objects
use an STL container. E.g.
std::list<A> my_list;
std::vector<A> my_vector;
The advantages of these are that you get a rich set of functionality,
instead of prmitive arrays, and you don't have to remember to clean up these
object you won't get memory leaks.
> Since how many number of the objects are
> unknown until runtime, probably it is not a good idea to create like:
>
> class A;
>
> A a[SIZE];
> ...
>
> How would like to code this? Thanks!
>
std::vector<A> my_vector(SIZE);
john
|