title: Error : non-lvalue in assignment
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Array
  {
     friend ostream &amp;operator&lt;&lt;( ostream &amp;, const Array &amp; );
  public:
     Array( int = 5 ); 
     Array( const Array &amp; ); 
     ~Array(); 
     int getSize() const; 
     const Array &amp;operator=( const Array &amp; );
     // subscript operator for non-const objects returns modifiable lvalue
     int &amp;operator[]( int );              
     // subscript operator for const objects returns rvalue
     int operator[]( int ) const;  
  private:
     int size; 
     int *ptr; 
  }; 
  
  Array::Array( int arraySize )
  {
     size = ( arraySize &gt; 0 ? arraySize : 5 ); // validate arraySize
     ptr = new int[ size ]; 
  
     for ( int i = 0; i &lt; size; i++ )
        ptr[ i ] = 0; 
  }
  
  // must receive a reference to prevent infinite recursion
  Array::Array( const Array &amp;arrayToCopy ) 
     : size( arrayToCopy.size )
  {
     ptr = new int[ size ]; // create space for pointer-based array
  
     for ( int i = 0; i &lt; size; i++ )
        ptr[ i ] = arrayToCopy.ptr[ i ]; // copy into object
  } 
  
  Array::~Array()
  {
     delete [] ptr; // release pointer-based array space
  } 
  
  int Array::getSize() const
  {
     return size; // number of elements in Array
  } 
  
  const Array &amp;Array::operator=( const Array &amp;right )
  {
     if ( &amp;right != this ) // avoid self-assignment
     {
        if ( size != right.size )
        {
           delete [] ptr; // release space
           size = right.size; // resize this object
           ptr = new int[ size ]; // create space for array copy
        }
  
        for ( int i = 0; i &lt; size; i++ )
           ptr[ i ] = right.ptr[ i ]; // copy array into object
     }
  
     return *this; 
  }
  
  // overloaded subscript operator for non-const Arrays reference return creates a modifiable lvalue
  int &amp;Array::operator[]( int subscript )
  {
  cout &lt;&lt; " ***************Inside non-sonstant operator[] function: Lvalue test*********** ";
     if ( subscript &lt; 0 || subscript &gt;= size )
     {
        cerr &lt;&lt; "\nError: Subscript " &lt;&lt; subscript 
           &lt;&lt; " out of range" &lt;&lt; endl;
        exit( 1 ); // terminate program; subscript out of range
     }
  
     return ptr[ subscript ]; // reference return
  }
  
  // overloaded subscript operator for const Arrays const reference return creates an rvalue
  int Array::operator[]( int subscript ) const
  {
  cout &lt;&lt; " ***************Inside sonstant operator[] function: Rvalue test*********** ";
     if ( subscript &lt; 0 || subscript &gt;= size )
     {
        cerr &lt;&lt; "\nError: Subscript " &lt;&lt; subscript 
           &lt;&lt; " out of range" &lt;&lt; endl;
        exit( 1 ); 
     } 
  
     return ptr[ subscript ]; // returns copy of this element
  }
  
  
  // overloaded output operator for class Array 
  ostream &amp;operator&lt;&lt;( ostream &amp;output, const Array &amp;a )
  {
     int i;
     // output private ptr-based array 
     for ( i = 0; i &lt; a.size; i++ )
     {
        output &lt;&lt; a.ptr[ i ] &lt;&lt; " ";
  
        if ( ( i + 1 ) % 4 == 0 )
           output &lt;&lt; endl;
     } // end for
  
     if ( i % 4 != 0 ) 
        output &lt;&lt; endl;
  
     return output; 
  } 
  
  int main()
  {
     Array integers1( 4 ); 
     Array integers2; // 5-element Array by default
     const Array&amp; integers4=integers1;
      //integers4[3] = 2000; //Error : non-lvalue in assignment 
      integers1 = integers1;  //valid
      integers4 = integers1;  //Error : binary '=' : no operator found 
      //which takes a left-hand operand of type 'const Array' (or there is no 
      //acceptable conversion)
      cout &lt;&lt; "\nintegers1[3] is " &lt;&lt; integers4[ 3 ];
  
     return 0;
  } 
  </code></pre>
  
  <p>Gives errors :</p>
  
  <p><strong>1)</strong>
  In function `int main()':</p>
  
  <p>'=' : left operand must be l-value</p>
  
  <p><strong>2)</strong>
  binary '=' : no operator found 
          which takes a left-hand operand of type 'const Array' (or there is no 
          acceptable conversion)    </p>
  
  <p>Please help. </p>