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 > how to initialize an stl iterator in vc2005
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
how to initialize an stl iterator in vc2005

Réponse
 
LinkBack Outils de la discussion
Vieux 01/07/2008, 13h41   #1
thinktwice
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how to initialize an stl iterator in vc2005

std::vector<CString> vec;
vec::iterator iter;

i can initiaze the iterator in vc6 like this $B!'(B iter = NULL, but it
compile failed in vc2005, it tells me there is no acceptable
conversion.


  Réponse avec citation
Vieux 01/07/2008, 14h00   #2
Stefan Naewe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to initialize an stl iterator in vc2005

On 7/1/2008 2:41 PM, thinktwice wrote:
> std::vector<CString> vec;
> vec::iterator iter;
>
> i can initiaze the iterator in vc6 like this : iter = NULL, but it
> compile failed in vc2005, it tells me there is no acceptable
> conversion.


How true...
Repeat after me: "An iterator is not a pointer".

Try this:


std::vector<CString> vec;
std::vector<CString>::iterator iter = vec.end();



What problem do you try to solve?


Regards,
Stefan
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
  Réponse avec citation
Vieux 02/07/2008, 02h06   #3
thinktwice
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to initialize an stl iterator in vc2005

thanks for your reply, i want to use a class data member whhose type
is a iteraotr, i might use in several class methods, but before use it
i want to know whether this iterator is null or invalid

On 7ÔÂ1ÈÕ, ÏÂÎç9ʱ00·Ö, Stefan Naewe <nos...@please..net> wrote:
> On 7/1/2008 2:41 PM, thinktwice wrote:
>
> > std::vector<CString> vec;
> > vec::iterator iter;

>
> > i can initiaze the iterator in vc6 like this £º iter = NULL, but it
> > compile failed in vc2005, it tells me there is no acceptable
> > conversion.

>
> How true...
> Repeat after me: "An iterator is not a pointer".
>
> Try this:
>
> std::vector<CString> vec;
> std::vector<CString>::iterator iter = vec.end();
>
> What problem do you try to solve?
>
> Regards,
> Stefan
> --
> Stefan Naewe stefan dot naewe at atlas-elektronik dot com
> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
> Plain text mails only, please http://www.expita.com/nomime.html


  Réponse avec citation
Vieux 02/07/2008, 03h07   #4
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to initialize an stl iterator in vc2005

thinktwice wrote:

> thanks for your reply, i want to use a class data member whhose type
> is a iteraotr, i might use in several class methods, but before use it
> i want to know whether this iterator is null or invalid


(a) Please don't top-post.

(b) Generally, it is impossible to determine through inspection whether an
iterator is invalid. The point is that operations on the underlying
container can invalidate iterators. The iterator is not required to detect
that.

(c) With a lot of care, you could use the container.end() value to indicate
an invalid iterator. However, this is fragile because of the problems
mentioned in (b).

(d) It might be better to consider a redesign that avoids the need for
checking the validity of the iterator. What is the underlying problem you
are trying to solve?


Best

Kai-Uwe Bux

> On 7?1?, ??9?00?, Stefan Naewe <nos...@please.net> wrote:
>> On 7/1/2008 2:41 PM, thinktwice wrote:
>>
>> > std::vector<CString> vec;
>> > vec::iterator iter;

>>
>> > i can initiaze the iterator in vc6 like this ? iter = NULL, but it
>> > compile failed in vc2005, it tells me there is no acceptable
>> > conversion.

>>
>> How true...
>> Repeat after me: "An iterator is not a pointer".
>>
>> Try this:
>>
>> std::vector<CString> vec;
>> std::vector<CString>::iterator iter = vec.end();
>>
>> What problem do you try to solve?
>>
>> Regards,
>> Stefan
>> --
>> Stefan Naewe stefan dot naewe at atlas-elektronik dot com
>> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
>> Plain text mails only, please http://www.expita.com/nomime.html


PS: also please don't quote signatures.

  Réponse avec citation
Vieux 02/07/2008, 10h14   #5
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to initialize an stl iterator in vc2005

On Jul 1, 2:41 pm, thinktwice <memorial...@gmail.com> wrote:
> std::vector<CString> vec;
> vec::iterator iter;


> i can initiaze the iterator in vc6 like this ? iter = NULL, but it
> compile failed in vc2005, it tells me there is no acceptable
> conversion.


It's undefined behavior. VC 6.0 failed to tell you about the
error; later versions do.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
  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 03h01.


É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,14562 seconds with 13 queries