title: Sparse Matrix, overloading= c++
body: <p>I need to overload <code>= operator</code> in my class SparseMatrix.</p>
  
  <pre><code>template &lt;class T&gt;
  class SparseMatrix
  {
  
    public:
    template &lt;class T&gt;
    class element
    {
    public:
        int x;
        int y;
        T val; 
        element(T war, int x1, int y1) { val = war; x = x1; y = y1; };
     };
  
    vector&lt;element&lt;T&gt;&gt; diff; //contains a cell with diffrent value
    T value; //contains a value of all cells at begining.
    int sizeX;
    int sizeY;
  
    SparseMatrix(T val, int x, int y) { value = val; sizeX = x; sizeY = y; };
    ~SparseMatrix() {};
  
    T&amp; operator()(int t, int t1)
    {
      for (int x = 0; x &lt; diff.size(); x++)
      if (diff[x].x == t &amp;&amp; diff[x].y == t1)
          return diff[x].val;
      return value;
    }
  };
  </code></pre>
  
  <p>If I type <code>mat(1,1) = 5</code>, program make a new element with parameters <code>x=1</code>, <code>y=1</code>, <code>val=1</code> and push back this element in vector diff. </p>