CS202 6- ‹#›
Overloading [] Operator
nThe subscript operator should be overloaded as a member; the first operand must be an object of the class
nTo be consistent, the second operand should be an integer index. Passed by value as it isn’t changed by the operator.
nSince the first operand is not modified (i.e., the current object is not modified), it should be specified as a constant member -- although exceptions are common.
nThe residual value should be the data type of the “element” of the “array” being indexed, by reference.
nThe residual value is an lvalue -- not an rvalue!