[Solved] Difference between the two?


An operator is a function which can be represented with a special syntax. So the following, if defined on a class MyClass:

T MyClass::operator% (int k);

can be called as follows:

MyClass a;
int k = 1;
T answer = a % k;

The other operator:

T MyClass::operator[] (int k);

Can be called by:

T answer = a[k];

By convention the % operator is called the modulo operator, while the [] operator is called the subscript operator, but you as they are just functions you can redefine them to make them do what you like.

3

solved Difference between the two?