C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to specify dynamic object names ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
vivekian
Guest





PostPosted: Tue Nov 29, 2005 12:27 am    Post subject: How to specify dynamic object names ? Reply with quote



Have to create a linked list of objects of the same type based on user
input. The number of objects in the list is dynamic depending on the
number input from the user. What would be the best way to name these
objects ?

Thanks,
vivekian

Back to top
/Gogineni/
Guest





PostPosted: Tue Nov 29, 2005 4:18 am    Post subject: Re: How to specify dynamic object names ? Reply with quote



Quote:
What would be the best way to name these objects
you will be accessing the linked list with a single pointer pointing to

the start of the list. You don't require to store names for each
object.
If you save each object name and use it what is the need for linked
list then.


Back to top
roberts.noah@gmail.com
Guest





PostPosted: Tue Nov 29, 2005 4:25 am    Post subject: Re: How to specify dynamic object names ? Reply with quote




/Gogineni/ wrote:
Quote:
What would be the best way to name these objects
you will be accessing the linked list with a single pointer pointing to
the start of the list. You don't require to store names for each
object.
If you save each object name and use it what is the need for linked
list then.

Depending on the behavior the OP is looking for (queue vs. stack) they
might want a second ptr at the tail. I'm sure you know this - more for
the OP.


Back to top
Howard
Guest





PostPosted: Tue Nov 29, 2005 3:48 pm    Post subject: Re: How to specify dynamic object names ? Reply with quote


"vivekian" <viveklinux (AT) gmail (DOT) com> wrote

Quote:
Have to create a linked list of objects of the same type based on user
input. The number of objects in the list is dynamic depending on the
number input from the user. What would be the best way to name these
objects ?


What do you mean by "name these objects"? Given the following:

struct AClass
{
std::string myName;
AClass( const char* theName ) : myName( theName ) {}
};

AClass specificClass;

What is the "name" you're referring to? Is it the class name "AClass", the
member "myName", or the variable name "specificClass"?

Given an answer to that, what does it have to do with the user specifying
the number of objects, as your question stated? Where does dynamically
naming the objects come into play?

-Howard



Back to top
vivekian
Guest





PostPosted: Tue Nov 29, 2005 8:57 pm    Post subject: Re: How to specify dynamic object names ? Reply with quote

Howard wrote:
Quote:
What do you mean by "name these objects"? Given the following:

struct AClass
{
std::string myName;
AClass( const char* theName ) : myName( theName ) {}

};

AClass specificClass;

I refer to the variable name specificClass. That is the naming of the
objects of the type AClass. The user input will be the number of AClass
objects to be created. This number is accepted at runtime.

I am not sure , but maybe i dont need to name these objects at all.
Would something like

AClass * temp ;
temp = new AClass () ;

do the trick . Then i can just link temp in the linked list as a node
and keep creating for the number of objects specified. Hope i am clear.
Maybe am thinking along the wrong lines.

vivekian


Back to top
Howard
Guest





PostPosted: Tue Nov 29, 2005 9:46 pm    Post subject: Re: How to specify dynamic object names ? Reply with quote


"vivekian" <viveklinux (AT) gmail (DOT) com> wrote

Quote:
Howard wrote:
What do you mean by "name these objects"? Given the following:

struct AClass
{
std::string myName;
AClass( const char* theName ) : myName( theName ) {}

};

AClass specificClass;

I refer to the variable name specificClass. That is the naming of the
objects of the type AClass. The user input will be the number of AClass
objects to be created. This number is accepted at runtime.

I am not sure , but maybe i dont need to name these objects at all.

Probably not.

Quote:
Would something like

AClass * temp ;
temp = new AClass () ;

do the trick . Then i can just link temp in the linked list as a node
and keep creating for the number of objects specified. Hope i am clear.

That would work fine (but you can combine it into one line inside your
loop). If a linked list of your own making is not required (i.e., for
homework), then you should consider using std::list (or whatever container
is appropriate) to hold the pointers. And, if you have the Boost libraries,
you could use their smart pointer class instead of using raw pointers like
your example.

Quote:
Maybe am thinking along the wrong lines.

vivekian




Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.