Re: Problem with pointers and iterators
- From: Pete Becker <pete@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 6 Oct 2008 17:01:43 -0400
On 2008-10-06 16:56:31 -0400, Griff Johns <no@xxxxxxxx> said:
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)
.
- Follow-Ups:
- Re: Problem with pointers and iterators
- From: Eric Sosman
- Re: Problem with pointers and iterators
- Prev by Date: Re: input word
- Next by Date: Re: input word
- Previous by thread: parameter order?
- Next by thread: Re: Problem with pointers and iterators
- Index(es):
Relevant Pages
|