Thread: What do these tow lines of code mean?

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    30

    Unhappy What do these two lines of code mean?

    Can someone explain these two lines of code please,

    Line one
    Code:
    T& operator[] (int i) {return at (i); }
    What is 'operator', and 'at'?

    Line Two
    Code:
    const T& operator[] (int i) const { return at(i);}
    What is going on here?

    Thanks!
    Last edited by Gamma; 04-25-2002 at 07:05 PM.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Meaning of Code Lines
    By shwetha_siddu in forum C Programming
    Replies: 4
    Last Post: 10-14-2008, 04:54 PM
  2. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  3. Replies: 7
    Last Post: 07-30-2005, 11:28 PM
  4. count only lines of code...
    By flightsimdude in forum C Programming
    Replies: 13
    Last Post: 09-23-2003, 07:08 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM