class group
{
int arr[15];
public:
///relevant code//
int&operator[](int i)
{
return arr[i];
}
\\relevant code
};
now if i have to access group elements through operator then i suppose that i should use syntax like ...
group g;
g[]i
or
[]gi
(because if i overload an operator then....we use syntax like....AoperatorB
or operator A B..where A and B are the operands)
but in the above case g[i] also works(other than g[]i
or
[]gi).....how???
plz explain...
thanks
Overloading operator[] is meant to give the same access syntax like normal arrays.
You can do g[i]
or g.operator[](i);
.
Last edited on