473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to initialize an stl iterator in vc2005

std::vector<CStringvec;
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.
Jul 1 '08 #1
4 3010
On 7/1/2008 2:41 PM, thinktwice wrote:
std::vector<CStringvec;
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<CStringvec;
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
Jul 1 '08 #2
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..netwrote:
On 7/1/2008 2:41 PM, thinktwice wrote:
std::vector<CStringvec;
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<CStringvec;
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
Jul 2 '08 #3
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.netwrote:
>On 7/1/2008 2:41 PM, thinktwice wrote:
std::vector<CStringvec;
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<CStringvec;
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.

Jul 2 '08 #4
On Jul 1, 2:41 pm, thinktwice <memorial...@gmail.comwrote:
std::vector<CStringvec;
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:ja*********@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
Jul 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: eric | last post by:
Hi, I would like to build the inParams SQLJ sample procedure from the Development Center. if I declare a #sql public iterator SpIterat, the Development Center complains this should be in a...
8
by: freckred76 | last post by:
Hi, I think this might be a VC++ problem. I am using Microsoft Visual Studio 2005 Full Version (8.0). I have a simple for loop that iterates over a list using the standard iterator. The...
4
by: Johan Pettersson | last post by:
Hi, I'm trying to "port" a project from VC++ 2003 to VC++ 2005 (Express Edition). This project contains the following code on several places (It is not exactly this code but a generalization of...
4
by: brianhray | last post by:
This works find in Dev Studio and Codewarrior but does not compile GCC4: template <class T> void SerializeVector(RArchive &ar, vector<T>& v) { for (vector<T>::iterator i = v.begin(); i !=...
3
by: wolverine | last post by:
Hi I am accessing a map from inside threads. There is a chance that an element is inserted into the map, from inside any thread. Since i don't know about thread safety of stl implementation i am...
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
4
by: arnuld | last post by:
i wrote a programme to create a vector of 5 elements (0 to 4), here is the code & output: #include <iostream> #include <vector> int main() { std::vector<intivec; // dynamically create a...
2
by: heng | last post by:
If the data member of a class is an array, how to initialize? I tried the following, but it is wrong. class A { public: int a; A():a({0,0,0}){} };
7
by: Jess | last post by:
Hello, I learned that if we do "v.end()", then the returned iterator is a temporary object and hence cannot be changed like --v.end(); Why is the returned iterator a temporary pointer? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.