title: Explain operator overloading in C++
body: <pre><code>class Vector { 
        public: 
         Vector(int s) :elem{new double[s]}, sz{s} { }
         double&amp; operator[](int i) { return elem[i]; } //function 2
         int size() { return sz; } 
  
          private: 
              double∗ elem;  
              int sz; 
       };
  </code></pre>
  
  <p>Code snippet from: <em>The C++ Programming Language 4th edition</em>, Bjarne Stroustrup<br/>
  IDE : Microsoft Visual Studio Professional 2013<br/></p>
  
  <p>Please explain what does the operator keyword do? I tried searching couldn't find anything else apart from operator overloading, which is not my question</p>
  
  <pre><code>double read_and_sum(int s) { 
                      Vector v(s);                     //line 1
                      for (int i=0; i!=v.size(); ++i) 
                      cin&gt;&gt;v[i];                        //line 3
                      double sum = 0; 
                      for (int i=0; i!=v.size(); ++i) 
                      sum+=v[i];
                       return sum;
                      }
  </code></pre>
  
  <p>Here line1 passes the argument "s" of int type needed by constructor of class vector , that's fine.</p>
  
  <p>But in line3 how can the statement "cin>>v[i]" be valid ? , since the object v isn't declared as an array of objects. Even if it is valid where does the value go..?</p>