title: operator overloading opertator + cant convert from pointer to const
body: <blockquote>
    <p>i have a sparse matrix that is created with two arrays and each array index have a linked list the non zero numbers are in there including the i and j indexs</p>
  </blockquote>
  
  <p><strong>the header</strong></p>
  
  <pre><code>class MNode {
  public:
  
      double _data;
  int _indexI, _indexJ; // the place of the node in the matrix 
                        // clarification: _nextRow is a pointer to the next columns in the row  
  MNode* _nextRow, *_nextCol;
  
  MNode(double data, int i, int j);
  };
  
  
  private:
  string _type;
  MNode** _rowHead, **_colHead; 
  int _rowSize, _colSize; 
  int _elemNum;
  
  void setValue(int, int, double);
  
  void removeElement(int, int);
  void insertNode(MNode*);
  bool IsExist(int, int);
  
      void setElementByType(int i, int j, double data);
  
  public:
  // construct a 'rows X cols' matrix. 
  SMatrix(int rows, int cols,string type);
  
  // set the (i,j) element to be 'data' 
  void setElement(int i, int j, double data);
  
  
  
  // destroy this matrix. 
  ~SMatrix();
  
  double getElement(int, int);
  
  friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const SMatrix&amp; mat);
  SMatrix&amp; operator = (const SMatrix&amp; other);
  SMatrix &amp; operator+(const SMatrix &amp; other) const;
  </code></pre>
  
  <p>};</p>
  
  <blockquote>
    <p>the cpp here is the overloading + function i get an erorr
    <strong>cannot convert this pointer to const SMatrix to Smatrix&amp;</strong></p>
  </blockquote>
  
  <pre><code>    SMatrix &amp;SMatrix::operator +(const SMatrix&amp; other) const {
      SMatrix temp(3, 3, "any") ;
  
      if (other._rowSize == this-&gt;_rowSize&amp;&amp;other._colSize == this-&gt;_colSize&amp;&amp;other._type == this-&gt;_type) {
          for (int j = 0; j &lt; other._colSize; j++) {
              for (int i = 0; i &lt; other._rowSize; i++) {
                  temp.setElement(i, j, (other.getElement(i, j) + this-&gt;getElement(i, j)));
              }
          }
      }
  
      return temp;
  }
  </code></pre>
  
  <blockquote>
    <p>here is the contructor</p>
  </blockquote>
  
  <pre><code>SMatrix::SMatrix(int rows, int cols,string matType )
  {
  
  
  _type = matType;
  _rowSize = rows;
  _colSize = cols;
  _elemNum = 0;
  _rowHead = new MNode*[rows];
  if (!_rowHead)
  {
      cout &lt;&lt; "allocation error";
      exit(1);
  }
  _colHead = new MNode*[cols];
  if (!_colHead)
  {
      cout &lt;&lt; "allocation error";
      exit(1);
  }
  for (int i = 0; i &lt; rows; i++)
  {
      _rowHead[i] = NULL;
  }
  for (int i = 0; i &lt; cols; i++)
  {
      _colHead[i] = NULL;
  }
  </code></pre>
  
  <p>}</p>
  
  <blockquote>
    <p>iam not sure what i need to do the signature of the function is given and cant be chanbged any idea?</p>
  </blockquote>