i am getting a reference to a variable in my fucntion
funct(ABC);
void funct ( XYZ%26amp; x) {
// I need to store a pointer to ABC in a list.
Can u suggest an efficent way of doing this. Also I am not sure of the scope of ABC. Please adive
}
This is my first time with C++ STL. i am writing a function where I store pointers in a list.. Please help!!?
typedef struct _list
{
struct _list *next;
void *data;
} List;
List *list_of_data;
void funct(XYZ %26amp;x)
{
List *list_p;
list_p = (List *) malloc(sizeof(List));
list_p -%26gt; data = (void *)x;
list_p -%26gt; next = list_of_data;
list_of_data = list_p;
}
Reply:can u make your question a little clearer please
Reply:It depends on what you mean by list. The most straightforward list is an array, but I’m assuming you want an expandable list? In which case std::vectors would be useful. But that’s just an arbitrary list of pointers. Does each pointer have any significance to it? Do you attach a name or arbitrary number to each pointer? Then you’ll want a std::map.
Might be useful: http://cppreference.com/
One more thing. Is there a reason you pass a reference to your object as opposed to a constant pointer to it?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment