I've been reading up on class operators and came across the following example:
class Array {
public:
int& operator[] (unsigned i) { if (i > 99) error(); return data[i]; }
private:
int data[100];
};
Does this mean I can replace [
and ]
with whatever I want? For example, could I use parentheses?
Also, what is the significance of the ampersand in int& operator[]
?
On a slightly less important note, would it be syntactically correct to use int& operator []
instead of int& operator[]
?