473,323 Members | 1,622 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,323 software developers and data experts.

Re: Problem with pointers and iterators

On 2008-10-06 16:56:31 -0400, Griff Johns <no@spam.comsaid:
>
MyObjectList::iterator it;
for (it = list.begin(); it != list.end(); ++it) {
// I used to be able to do this:
MyObject* p_obj = it;
Foo(p_obj);

// Or this
Foo(it);

}

But now the error I get is 'cannot convert parameter 1 from
'std::vector<_Ty>::iterator' to 'MyObject *'
Write on the blackboard 100 times: "An iterator is not a pointer."

In VC6 this worked because vector::iterator was a typedef for T*. In
later versions that changed. Both forms satisfy the requirements of the
standard.

Well, you have an iterator that refers to an object, and you need the
address of that object. So there are two steps: get a reference from
the iterator, and take its address.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 6 '08 #1
4 2187
In article <2008100617014316807-pete@versatilecodingcom>,
Pete Becker <pe**@versatilecoding.comwrote:
[deleted]

For those baffled by this slew of messages, the original seems to have
been posted to comp.lang.c++ with followups set to comp.lang.c.
I'm posting this to both with followups set to comp.lang.c++ so
that it can be taken up over there.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Oct 6 '08 #2
Pete Becker wrote:
On 2008-10-06 16:56:31 -0400, Griff Johns <no@spam.comsaid:
>>
MyObjectList::iterator it;
[...]

Write on the blackboard 100 times: "An iterator is not a pointer."
[...]
Write on the blackboard 100 times: "C++ is not C," and then
consider using comp.lang.c++ for C++ discussions.

--
Er*********@sun.com
Oct 6 '08 #3
Eric Sosman wrote:
Pete Becker wrote:
>Griff Johns <no@spam.comsaid:
>>MyObjectList::iterator it;
[...]

Write on the blackboard 100 times: "An iterator is not a pointer."
[...]

Write on the blackboard 100 times: "C++ is not C," and then
consider using comp.lang.c++ for C++ discussions.
At last, a sane answer for c.l.c.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Oct 6 '08 #4
CBFalconer <cb********@yahoo.comwrote:
Eric Sosman wrote:
Pete Becker wrote:
Griff Johns <no@spam.comsaid:

MyObjectList::iterator it;
[...]

Write on the blackboard 100 times: "An iterator is not a pointer."
[...]
Write on the blackboard 100 times: "C++ is not C," and then
consider using comp.lang.c++ for C++ discussions.

At last, a sane answer for c.l.c.
For Nybbas' sake, Chuck, you don't _have_ to turn yourself into a
Looking-Glass Kenny!

Richard
Oct 7 '08 #5

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

Similar topics

11
by: Gianni Mariani | last post by:
I'm looking at templatizing some code that uses pointers and iterators. There are 3 kinds of values for pointers. - Null - Invalid ( the value is ((T*)-1) ) - Valid Null indicates that...
4
by: Leon | last post by:
Hi all. I'm a bit confused about the use of STL iterators and pointers, and I was wondering if maybe you could give me some pointers ;) Is it possible to convert between iterators and pointers...
12
by: Sims | last post by:
Hi, Here is the code that .NET does not seem to like, but as far as i can see it is valid C++ code. Am i wrong? .... // vector headers ....
8
by: He Shiming | last post by:
Hi, I've developed a class that implements an interface definition. It looks like this: class IRecord { public: // define interface methods by pure virtual methods // no member variables }
8
by: babak | last post by:
Hi everyone I have a problem with Iterators and containers in STL that hopefully someone can help me with. This is what I try to do: I have an associative (map) container and I have a...
8
by: Steve Lambert | last post by:
Hi, I'd be grateful if someone could clarify this for me. In the linked list structure my intention is to declare an array of length 3 containing pointers to node eg. Node *Iterators The...
4
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
5
by: jgscott | last post by:
I've been trawling around for an answer to this question and thought I'd try here. I have a class Graph, which has a std::list<Nodeas a class member. Node it itself a class that makes extensive...
4
by: pandit | last post by:
Hello i dont understand how to Deal with iterator. its little bit confusing ? how they work??
13
by: Javier | last post by:
Hello, I have some cuestions about constness with standard containers and pointers. Supose I have a list of pointers to some class B: std::list< B * list; I have readed that constness in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.