C++ copy constructor, assignment 'operator=' <p>I'm trying to make a copy constructor or = operator. If I define a matrix named A, another as B and C and use the '=' operator as:</p> <p>A=B</p> <p>it performs well, However if i use like: </p> <p>A=B+C i get this error: no matching function for '='. </p> <p>The point is when I change the symbol(=) to (==) it works well,even in the case of A == B+C, however by using only the equality sign(=) it doesn't work! any ideas?</p> <p>In the header file:</p> <pre><code>Simple2DMatrixD (const Simple2DMatrixD&amp; matrixA) { numRows = matrixA.numRows; numCols = matrixA.numCols; dataArray = new double[numRows * numCols]; for (int iX = 0; iX &lt; numRows; iX++) { for (int iY = 0; iY &lt; numCols; iY++) { dataArray[(iX * numRows) + iY] = matrixA.getElement(iX,iY) ; } } } Simple2DMatrixD &amp; assign (const Simple2DMatrixD &amp; matrixB); Simple2DMatrixD &amp; sum (const Simple2DMatrixD &amp; matrixA, const Simple2DMatrixD &amp; matrixB); </code></pre> <p>// ADDITION OPERATOR</p> <pre><code>friend Simple2DMatrixD operator+ (Simple2DMatrixD &amp; matrixA, Simple2DMatrixD &amp; matrixB) { Simple2DMatrixD matrixTemp(matrixA.numRows, matrixA.numCols); matrixTemp.sum(matrixA, matrixB); return (matrixTemp); } </code></pre> <p>// ASSIGNMENT OPERATOR</p> <pre><code>Simple2DMatrixD &amp; operator= (const Simple2DMatrixD &amp; matrixB) { this-&gt;assign(matrixB); return (*this); } </code></pre> <p>// and in the source file:</p> <pre><code>Simple2DMatrixD &amp; Simple2DMatrixD::assign (const Simple2DMatrixD &amp; matrixB) { for (int r = 0; r &lt; numRows; r++) { for (int c = 0; c &lt; numCols; c++) { this-&gt;setElement(r, c, matrixB.getElement(r, c)); } } return (*this); } </code></pre> <p>// MATRICES ADDITION</p> <pre><code>Simple2DMatrixD &amp; Simple2DMatrixD::sum (const Simple2DMatrixD &amp; matrixA, const Simple2DMatrixD &amp; matrixB) { // TODO REPLACE WITH COMPAREDIMENSION FUNCTION if ((this-&gt;numRows == matrixB.numRows) &amp;&amp; (this-&gt;numCols == matrixB.numCols) ) { for (int r = 0; r &lt; matrixA.numRows; r++) { for (int c = 0; c &lt; matrixA.numCols; c++) { this-&gt;setElement(r, c, matrixA.getElement(r, c) + matrixB.getElement(r, c)); } } return (*this); } else { throw " Dimensions does not match!"; } } </code></pre>