|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi
I have a class X and I'm using a list to store X instances. Later in the project I realized that I needed to search that list for certain instances and I thought of storing the found objects in a vector<X *>. My problem is - how can I run through list<X>, with a list<X>::iterator, and use a pointer to point to the selected objects? I'm thinking of rewriting all instances of list<X> and use list<X *> in order to be compatible with the search function. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Apr 3, 7:33 pm, André Castelo <andrecast...@gmail.com> wrote:
> Hi > > I have a class X and I'm using a list to store X instances. Later in > the project I realized that I needed to search that list for certain > instances and I thought of storing the found objects in a vector<X *>. > > My problem is - how can I run through list<X>, with a > list<X>::iterator, and use a pointer to point to the selected objects? > > I'm thinking of rewriting all instances of list<X> and use list<X *> > in order to be compatible with the search function. class X {}; std::list<X> myList; std::list<X>::iterator find = myList.begin(); X* pointer = &(*find); // * -> get a reference to the objct. & get the addrss. std::vector<X*> data; data.push_back(pointer); |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> X* pointer = &(*find);
Thanks, it worked! |
|
![]() |
| Outils de la discussion | |
|
|