Re: Problem with pointers and iterators

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pete Becker

    #1

    Re: Problem with pointers and iterators

    On 2008-10-06 16:56:31 -0400, Griff Johns <no@spam.comsai d:
    >
    MyObjectList::i terator 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<_T y>::iterator' to 'MyObject *'
    >
    Write on the blackboard 100 times: "An iterator is not a pointer."

    In VC6 this worked because vector::iterato r 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)

  • Richard Tobin

    #2
    Re: Problem with pointers and iterators

    In article <20081006170143 16807-pete@versatilec odingcom>,
    Pete Becker <pete@versatile coding.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.

    Comment

    • Eric Sosman

      #3
      Re: Problem with pointers and iterators

      Pete Becker wrote:
      On 2008-10-06 16:56:31 -0400, Griff Johns <no@spam.comsai d:
      >
      >>
      >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.

      --
      Eric.Sosman@sun .com

      Comment

      • CBFalconer

        #4
        Re: Problem with pointers and iterators

        Eric Sosman wrote:
        Pete Becker wrote:
        >Griff Johns <no@spam.comsai d:
        >>
        >>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.

        Comment

        • Richard Bos

          #5
          Re: Problem with pointers and iterators

          CBFalconer <cbfalconer@yah oo.comwrote:
          Eric Sosman wrote:
          Pete Becker wrote:
          Griff Johns <no@spam.comsai d:
          >
          >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

          Comment

          Working...