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 > vector of class
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
vector of class

Réponse
 
LinkBack Outils de la discussion
Vieux 30/06/2008, 17h34   #1
xyz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut vector of class

i have a vector of certain class which has certain parameters
xxx is my class
and here is my vector
std::vector<xxx > yyy;

in my vector i have the data as below:
12 abcde 34567 asdf 1
13 fjggkf 2343 fkjhk 3
12 fgfgfh 33434 fgh 2
34 dgdg 5454 fgfdg 2
.....
now i want to iterate through my vector inorder i have to delete 2nd
line in my vector
here is my iterator which goes through all elements of my vector

std::vector<xxx >::iterator iter;

i could able to do with the integer vector but i have problem with the
vector of certain class
thank you for any
  Réponse avec citation
Vieux 30/06/2008, 18h39   #2
Daniel T.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector of class

On Jun 30, 12:34pm, xyz <lavanyaredd...@gmail.com> wrote:

> i have a vector of certain class which has certain parameters
> xxx is my class
> and here is my vector
> std::vector<xxx > yyy;
>
> in my vector i have the data as below:
> 12 abcde 34567 asdf 1
> 13 fjggkf 2343 fkjhk 3
> 12 fgfgfh 33434 fgh 2
> 34 dgdg 5454 fgfdg 2
> ....
> now i want to iterate through my vector inorder i have to delete 2nd
> line in my vector
> here is my iterator which goes through all elements of my vector
>
> std::vector<xxx >::iterator iter;
>
> i could able to do with the integer vector but i have problem with the
> vector of certain class


You do it the same way.

> thank you for any


Use the erase-remove idiom. If your class defines an operator== that
can compare two of them for equivelance, then simply:

yyy.erase(remove(yyy.begin(), yyy.end()), yyy.end());

If your class doesn't have an op==, then you will have to define a
predicate that returns true for the value(s) that needs to be removed
and use the remove_if algorithm:

bool mypred(const xxx& left, const xxx& right);
// returns true is left is like right.

yyy.erase(remove_if(yyy.begin(), yyy.end(), &mypred), yyy.end());

You could also use a function object (functor) for "mypred", possibly
even compose one from the standard ones that exist or using something
like the boost lambda library.
  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 03h49.


É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,33575 seconds with 10 queries