Hello,
I have a short matrix class I am trying to set up for a small project. I would like to overload the + operator to simplify the code syntax. However I am running into a compilation issue that I am not familiar with. Here is a snippet of the relevant code:
And here is the error I am receiving from the compiler:
Matrix.h: In member function `FlightSim::Mat rixFlightSim::M atrix::operator +(FlightSim::Ma trix&)':
Matrix.h:78: `A' cannot be used as a function
make: *** [Matrix.o] Error 1
I should mention that I am fairly new at C++ so I recognize my inexperience is sure to be a factor here.
Thanks!
I have a short matrix class I am trying to set up for a small project. I would like to overload the + operator to simplify the code syntax. However I am running into a compilation issue that I am not familiar with. Here is a snippet of the relevant code:
Code:
// File Matrix.h
class Matrix
{
public:
Matrix(int Rows);
Matrix(int Rows, int Columns);
~Matrix();
double &operator() (int Row, int Column)
{
if(Row < 0 || Column < 0 || Row > mRows || Column > mColumns)
{
// Out of range error
}
return(mData[(mColumns * Row) + Column]);
}
Matrix operator + (Matrix &B)
{
Matrix *A = this;
if((A->GetRowCount() != B.GetRowCount()) ||
(A->GetColCount() != B.GetColCount()))
{
// Matrices do not have the same dimensions
return(*A);
}
Matrix C(A->GetRowCount(), A->GetColCount());
for(int i = 0; i < A->GetRowCount(); ++i)
{
for(int j = 0; j < A->GetColCount(); ++j)
{
C(i, j) = A(i, j) + B(i, j); // This is line 78 as referenced by the error below
}
}
return(C);
}
private:
int mRows;
int mColumns;
double *mData;
}
Matrix.h: In member function `FlightSim::Mat rixFlightSim::M atrix::operator +(FlightSim::Ma trix&)':
Matrix.h:78: `A' cannot be used as a function
make: *** [Matrix.o] Error 1
I should mention that I am fairly new at C++ so I recognize my inexperience is sure to be a factor here.
Thanks!
Comment