Difference between a const iterator and const_iterator

This is a discussion on Difference between a const iterator and const_iterator within the C++ Programming forums, part of the General Programming Boards category; Well, I had a question in my book asking this. I was wondering if this is right?: "You would use ...

  1. #1
    gin
    gin is offline
    Hmm...? gin's Avatar
    Join Date
    Jun 2008
    Location
    Glasgow, Scotland
    Posts
    51

    Difference between a const iterator and const_iterator

    Well, I had a question in my book asking this. I was wondering if this is right?:

    "You would use an iterator that is const when you will just be reading/writing from ONE element in a container. You would use const_iterator when you will just be READING from one or more elements in a container. The difference between them is the fact a const iterator's location cannot be changed where as with a const_iterator the value of the location cannot be changed."

    Am I on right track here? (I hope you don't mind me asking all these questions here, but I want to make sure I'm getting all this) Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,954
    A const_iterator is a misnomer for an "iterator to const". What your book means by a "const iterator" is an iterator that is const. Your interpretation sounds correct, though you can modify an object using an iterator that is const, assuming that what it points to is not const.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes & Collections
    By Max_Payne in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 12:06 PM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM
  4. vector<>
    By teval in forum C++ Programming
    Replies: 11
    Last Post: 08-18-2003, 03:27 PM
  5. difference between: const char *, char *
    By creeping_death in forum C Programming
    Replies: 3
    Last Post: 08-04-2003, 11:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21