PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Iterator to pointer?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Iterator to pointer?

Réponse
 
LinkBack Outils de la discussion
Vieux 04/04/2008, 03h33   #1
André Castelo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Iterator to pointer?

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.
  Réponse avec citation
Vieux 04/04/2008, 03h55   #2
Martin York
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Iterator to pointer?

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);
  Réponse avec citation
Vieux 04/04/2008, 04h08   #3
André Castelo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Iterator to pointer?

> X* pointer = &(*find);

Thanks, it worked!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10089 seconds with 11 queries