   Iterators and Classes, methods access question
  Hi everyone,i have a rather basic problem i cant get my head around! i trust this will be a piece of cake for most of you! Here goes:class customclass{private:int value2;public:int value1;customclass(){value1 = 1;value2 =10;}customclass(int i) {value1=i;value2=10;}int return_value2(){ return value2;}};std::list<customclass> list_of_classes;void main(){customclass objekt(1);customclass objekt2(3);customclass objekt3(4);customclass objekt4(2);list_of_classes.push_front(objekt);list_of_classes.push_front(objekt2);list_of_classes.push_front(objekt3);list_of_classes.push_front(objekt4);std::list<customclass>::const_iterator iterator;for(iterator=list_of_classes.begin(); iterator!=list_of_classes.end(); ++iterator){printf("%d,",iterator->value1); //this works!printf("%d,",iterator->return_value2());  //this does not!printf("%d,",*iterator->return_value2());  //this does not!} getchar();}The question is: how do i access the methods of my class through iterators? He seems not to have problems with retrieving public variables from my objects, but i cant seem to run any class methods like return_value2()!?Any suggestions on how would i go about doing this?   
  Since you are using a const_iterator, you can only access const methods of the class through this iterator. So declare the getter so (as getters generally should be):int get_sth() const {return some_value };  it works! Simple and quick! Thx a lot!   ;  A few notes-by-example about writing modern C++, and about simplifying code in general.class custom {  int value2;  public:  int value1;  custom(int i = 1) : value1(i), value2(10) {}  // The 'const' here, of course, is the part you were missing. :)  int get_value2() const { return value2; }};int main() {  std::list<custom> objects;  // It's usual to use push_back() instead for this kind of thing; then you  // can add things in the same order that they will end up in.  objects.push_front(custom(1));  objects.push_front(custom(3));  objects.push_front(custom(4));  objects.push_front(custom(2));  typedef typename std::list<custom>::const_iterator iterator;  for (iterator it = objects.begin(), end = objects.end(); it != end; ++it) {    std::cout << it->value1 << ", " << it->get_value2();  }  // Don't pause programs artificially at the end.};  Thanks for the tips Zahlman, i am analysing your code and trying to modernize my project:)I am not sure if you are aware that the line:   typedef typename std::list<custom>::const_iterator iterator;did not work(i got 'typename cannot be used outside a template declaration'), but this did:   typedef std::list<custom>::const_iterator iterator;so it goes without the 'typename'. Im still a learning a lot about c++ but i presume you simplified the declaration of the iterator to make it more readable?   