title: operator overloading in c++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4421706/operator-overloading">Operator overloading</a>  </p>
  </blockquote>
  
  
  
  <p>Hi guys can some one please suggest a good tutorial on operator overloading?<br>
  I was going through this code on operator overloading and I have the following doubts<br>
  <b>code:</b></p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class Array {
  
   int *a;
   int size;
   int capacity;
  
   public:
      Array (int c) {a=new int[c]; size=0; capacity =c; } ;
      Array &amp; operator &lt;&lt;  (int x); 
      int  operator []  (int i) { 
          if (i&lt;size) return a[i] ;
          else  {
              cout &lt;&lt;"Segmentation Fault Prevented!\n"; 
              return -1;
          }
      };
  };
  Array &amp;Array::operator &lt;&lt;  (int x) { 
     if (size &lt; capacity) a[size++] = x;
     else {
      int *tmp = new int[size+capacity];
      for (int j=0; j&lt;size; j++)
          tmp[j]=a[j];
      delete [] a;
      a = tmp;
      a[size++]=x;
      capacity=size+capacity;
     }
     return *this;
  
  } ; 
  
  int main (int agrc, char *argv[] ) {
  
   Array b(10);
  
      for (int i=0; i&lt;100; i++) b &lt;&lt; i;
      b &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; 3;
      for (int i=0; i&lt;105; i++) cout &lt;&lt; b[i] &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I have these doubts:</p>
  
  <ol>
  <li>Can some one please suggest a good tutorial on operator overloading?</li>
  <li>what does <code>Array &amp; operator &lt;&lt;  (int x);</code> mean?</li>
  <li><code>int operator []  (int i)</code> - if this is a function why are we putting square brackets here?</li>
  <li><code>Array &amp;Array::operator</code> means what?</li>
  <li>what is <code>*this</code>?</li>
  </ol>
  
  <p>Please help me...I am new to c++ so have these doubts....
  Thanks in advance</p>