I've got a program that I believe uses correct syntax, however in Visual studio 2005 it compiles fine, and in dev-cpp 4.9.9.2 it gives me an error. my code is this:
Code:
// main.cpp
//proper includes...
int main()
{
Matrix m1(3,3), m2(3,3), m3;
Matrix m4(2,3);
m3 = m1 + m2;
return 0;
}
*******************************
// Matrix.h
// proper includes
// MatrixException class
class Matrix
{
// private stuff
public:
// constructor destructor and everything else
// i'm having trouble with these 2 things:
Matrix(Matrix &m);
void operator = (Matrix &m);
};
************************************
// Matrix.cpp
// proper includes
// all functions defined properly, except these two:
Matrix::Matrix(Matrix &m)
{
numRows = m.numRows;
numCols = m.numCols;
data = new int[numRows*numCols];
for (int i=0; i < numRows*numCols ; i++)
data[i] = m.data[i];
}
void Matrix::operator = (Matrix &m)
{
numRows = m.numRows;
numCols = m.numCols;
data = new int[numRows*numCols];
for (int i=0; i < numRows*numCols ; i++)
data[i] = m.data[i];
}
now everything works fine except in main, where i say
dev's compiler tells me
Code:
...main.cpp no match for 'operator=' in 'm3 = Matrix::operator+(Matrix&)(((Matrix&)(&m2)))'
note D:\School\Semester 3\CPS271\Matrix Class Lab\Matrix.h:50 candidates are: void Matrix::operator=(Matrix&)
but that is my only error. any suggestions?