Re: Problem with pointers and iterators

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

    #1

    Re: Problem with pointers and iterators

    Griff Johns writes:
    >
    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 *'
    >
    This is after migrating a project from vc6.0 to vc7.1, but I think that
    the issue lies with the language standards(?).
    Correct.
    So why does this happen
    now,
    Because an iterator is not a pointer. An iterator is an object of its own.
    and how do I resolve it?
    In most cases, the easiest thing to do would be "MyObject *p= &*it;".



    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEABECAAYFAkj qgVsACgkQx9p3GY HlUOIEiACeI8sQ5 o/j2PF/kmGY7f/tU33D
    erIAniaY62OoZTp BtHvA/xmqxg8jKkKj
    =rfhH
    -----END PGP SIGNATURE-----

Working...