Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Creating objects

Reply
Thread Tools

Creating objects

 
 
ikl
Guest
Posts: n/a
 
      04-07-2004
When creating a list of objects of the same class, what should be concerned
to decide if using "new" or not? 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!


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      04-07-2004

"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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating garbage collectable objects (caching objects) News123 Python 7 06-29-2009 04:12 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
Inheritance of objects within objects Simon Elliott C++ 2 12-10-2004 10:59 AM
objects of objects, vectors and sessions bigbinc Java 3 11-18-2003 09:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57