Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Vector index to iterator

Vector index to iterator

Scheduled Pinned Locked Moved C / C++ / MFC
databasegraphicshelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elelont2
    wrote on last edited by
    #1

    Hi, i am trying to point my vector iterator to some vector index like this: std::vector::iterator* it= myVec[i]; But it fails: no known conversion for argument 1 from ‘Data’ to ‘std::vector::iterator Please help :)

    _ 1 Reply Last reply
    0
    • E elelont2

      Hi, i am trying to point my vector iterator to some vector index like this: std::vector::iterator* it= myVec[i]; But it fails: no known conversion for argument 1 from ‘Data’ to ‘std::vector::iterator Please help :)

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      std::vector<int>::iterator it = myVec.begin() + i;

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      E 1 Reply Last reply
      0
      • _ _Superman_

        std::vector<int>::iterator it = myVec.begin() + i;

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        E Offline
        E Offline
        elelont2
        wrote on last edited by
        #3

        Thank you, but can you explain why my version does not work? Are the types not compatible? I can access vector elements by dereferencing iterators, does it not work the other way around?

        C 1 Reply Last reply
        0
        • E elelont2

          Thank you, but can you explain why my version does not work? Are the types not compatible? I can access vector elements by dereferencing iterators, does it not work the other way around?

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          It doesn't work because it is wrong.

          Quote:

          std::vector::iterator* it= myVec[i];

          You are trying to assign a value (not an address) to an iterator. Please note, even

          std::vector::iterator* it= &myVec[i];

          Would NOT WORK, because iterators are not exactly pointers.

          THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups