title: c++: overloading + operator for a sparse matrix
body: <pre><code>void add(sparseMatrix&lt;T&gt; &amp;b, sparseMatrix&lt;T&gt; &amp;c); // c is output
  
  sparseMatrix&lt;T&gt; operator+(sparseMatrix&lt;T&gt; &amp;b);
  </code></pre>
  
  <p>I'm creating a sparse matrix which is made up of an arrayList of singly linked lists of matrix terms (matrix terms contain the row, column, and value). I'm having trouble overloading the + operator. I have an add method which works fine, but when I try to use it to overload the + operator I get the following errors:</p>
  
  <pre><code>sparseMatrix.cpp: In function ‘int main()’:
  sparseMatrix.cpp:268: error: no match for ‘operator=’ in ‘c = sparseMatrix&lt;T&gt;::operator+(sparseMatrix&lt;T&gt;&amp;) [with T = int](((sparseMatrix&lt;int&gt;&amp;)(&amp; b)))’
  sparseMatrix.cpp:174: note: candidates are: sparseMatrix&lt;T&gt;&amp; sparseMatrix&lt;T&gt;::operator=(sparseMatrix&lt;T&gt;&amp;) [with T = int]
  make: *** [sparseMatrix] Error 1
  </code></pre>
  
  <p>Here is my implementation for the overloaded + operator:</p>
  
  <pre><code>sparseMatrix&lt;T&gt; sparseMatrix&lt;T&gt;::operator+(sparseMatrix&lt;T&gt; &amp;b) 
  {
          sparseMatrix&lt;T&gt; c;
  
   add(b, c);
   return c;
  
  }
  </code></pre>
  
  <p>The line in main that gives the error is c = a + b (a, b, c are all sparse matrices). Note that if I do a.add(b,c) everything works fine. I have also overloaded the = operator which works when I do a = b etc. but it seems to be complaining about it in the error message I posted. I'm really not sure what the problem is. Any ideas?</p>