Left and right bracket operators

I know how to implement the reading [] operators but I don't understand the ones to change values. i.e.:

 
int operator [](int i) const {return myarray[i];}


This is to read. And:

 
int& operator [](int i) {return myarray[i];}


is to modify. This is the part I don't get. How do you actually modify the array if the modification operator just returns the array element?
The second operator is passing back a reference to an int. This is a reference to the actual array element myarray[i], and is an lvalue. This means that if its value is changed, the value of the array element myarray[i] is changed.
Last edited on
Topic archived. No new replies allowed.