Can someone explain these two lines of code please,
Line one
What is 'operator', and 'at'?Code:T& operator[] (int i) {return at (i); }
Line Two
What is going on here?Code:const T& operator[] (int i) const { return at(i);}
Thanks!
Can someone explain these two lines of code please,
Line one
What is 'operator', and 'at'?Code:T& operator[] (int i) {return at (i); }
Line Two
What is going on here?Code:const T& operator[] (int i) const { return at(i);}
Thanks!
Last edited by Gamma; 04-25-2002 at 07:05 PM.
I am not sure if I can explain this good enough but it is operator overloading of [].
operator is a key word telling the compiler that what is following should be done when the "operator" is found. In this case [] but it could be /*-+ to. at is a function i is the argument; It makes it possible to do things like
CString one; //Object of CString class
CString two; //Object of CString class
one = one + two; //Use the overloaded operators = and + to do something with the CString objects.