Have a look at the following code fragment: myclass a( 3 ); cout<<a[ 0 ]; Doesn’t it look awkward! Yes it does, because we have overloaded he [] operator and given it some special meaning. In C++, it is possible to overload the [] operator and give it a different meaning rather then the usual object indexing. The general form for overloading [] operator is: ret-type operator []( int ); It is considered a binary operator hence when declared as a member, it accepts one explicit argument (usually int ). Although you are free to accept any type of argument but sticking to the original concept of indexing, it would always be an integer. ob[i]; When the compiler encounters the above expression (with the [] operator overloaded) the [] operator function is called as below: ob.operator[] (1) The argument ‘1’ is passed explicitly while ‘ob’ is passed implicitly using the ‘this’ pointer. Enough discussio...
A resource for learning PHP, HTML, CSS, JavaScript, C++, etc.