| View previous topic :: View next topic |
| Author |
Message |
vivekian Guest
|
Posted: Tue Nov 29, 2005 12:27 am Post subject: How to specify dynamic object names ? |
|
|
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
|
Posted: Tue Nov 29, 2005 4:18 am Post subject: Re: How to specify dynamic object names ? |
|
|
| 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
|
Posted: Tue Nov 29, 2005 4:25 am Post subject: Re: How to specify dynamic object names ? |
|
|
/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
|
Posted: Tue Nov 29, 2005 3:48 pm Post subject: Re: How to specify dynamic object names ? |
|
|
"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
|
Posted: Tue Nov 29, 2005 8:57 pm Post subject: Re: How to specify dynamic object names ? |
|
|
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
|
Posted: Tue Nov 29, 2005 9:46 pm Post subject: Re: How to specify dynamic object names ? |
|
|
"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 |
|
 |
|