I'm curious how I would go about overloading []. I have an exam tomorrow, and on last years exam the prof asked the following question:
Make a class that hold a private vector<int> - he then lists a bunch of requirements for the class, one of which is overloading the [] operator both ways so that you could go:
In order for foo[4] = 6; to work, operator[] has to return a non-const reference. Technically you could use the same method for the second line above too, however it is more usual to make a second operator[] that is a const method and returns the int by value instead of by reference.