[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Problem with pointers and iterators

Retoro

10/6/2008 8:57:00 PM

Hi, if I have the following code:
class MyObject
{
public:
MyObject() {};
~MyObject() {};

int x;

}

class MyObjectList : public std::vector<MyObject> {};

void Foo(MyObject* obj)
{
// Do something with obj->x

}

If I loop through it like this:

MyObjectList list;
// stuff list with objects

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 *'

This is after migrating a project from vc6.0 to vc7.1, but I think that
the issue lies with the language standards(?). So why does this happen
now, and how do I resolve it?

Thanks.

5 Answers

richard

10/6/2008 9:33:00 PM

0

In article <2008100617014316807-pete@versatilecodingcom>,
Pete Becker <pete@versatilecoding.com> wrote:
[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.

Default User

10/6/2008 10:00:00 PM

0

Griff Johns wrote:

Why in the hell did you set follow-ups to comp.lang.c?





Brian

Retoro

10/6/2008 10:06:00 PM

0

What do you mean? I'm posting this to comp.lang.c++ but the only two
replies have gone on about comp.lang.c for some reason.

This is a C++ question and I think this is the right place to post it?

On Mon, 06 Oct 2008 21:59:45 +0000, Default User wrote:
> Griff Johns wrote:
>
> Why in the hell did you set follow-ups to comp.lang.c?
>
>
>
>
>
> Brian

Default User

10/6/2008 10:15:00 PM

0

From: "Default User" <defaultuserbr@yahoo.com>
Subject: Re: Problem with pointers and iterators
Date: 6 Oct 2008 22:12:59 GMT
Newsgroups: comp.lang.c
User-Agent: XanaNews/1.17.5.9

Griff Johns wrote:

Don't top-post. Rearranged.

> On Mon, 06 Oct 2008 21:59:45 +0000, Default User wrote:
> > Griff Johns wrote:
> >
> > Why in the hell did you set follow-ups to comp.lang.c?
> What do you mean? I'm posting this to comp.lang.c++ but the only two
> replies have gone on about comp.lang.c for some reason.
>
> This is a C++ question and I think this is the right place to post it?

Here are the full headers from your message:

From: Griff Johns <no@spam.com>
Subject: Re: Problem with pointers and iterators
Date: Mon, 06 Oct 2008 23:05:36 +0100
Message-ID: <pan.2008.10.06.22.05.34.672271@spam.com>
References: <pan.2008.10.06.20.56.31.345683@spam.com>
<6kvg2hF9p5sqU1@mid.individual.net>
Lines: 16
Path: uni-berlin.de!fu-berlin.de!news.germany.com!aioe.org!not-for-mail
Newsgroups: comp.lang.c++
Followup-To: comp.lang.c
Organization: Aioe.org NNTP Server
NNTP-Posting-Host: N1FvpErgY0u8uU4+C0wjqA.user.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@aioe.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a
cleansing moment of clarity.)
Xref: uni-berlin.de comp.lang.c++:1031268



You have Followup-To set to another newsgroup, and that's where most of
the replies went.




Brian

red floyd

10/6/2008 10:23:00 PM

0

On Oct 6, 1:56 pm, Griff Johns <n...@spam.com> wrote:
> Hi, if I have the following code:
> class MyObject
> {
> public:
>    MyObject() {};
>    ~MyObject() {};
Delete the semicolons after constructor/destructor.
>
>    int x;
>
> }
>
> class MyObjectList : public std::vector<MyObject> {};
>
> void Foo(MyObject* obj)
> {
>    // Do something with obj->x
>
> }
>
> If I loop through it like this:
>
> MyObjectList list;
> // stuff list with objects
>
> 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 *'
>
> This is after migrating a project from vc6.0 to vc7.1, but I think that
> the issue lies with the language standards(?).  So why does this happen
> now, and how do I resolve it?


use Foo(&*it);