Solved

# operators and stuff

Posted on 2005-03-31

hi there,

I have a matrix class, I need to build an operator that will do

int main(){

matrix a,b;

.

.

.

a = b + 2;

.

.

return 0;

}

this one I got. I did it this way

matrix matrix::operator +(int x){

matrix sum(iRows,iColumns);

for(int i=0;i<getRows();i++){

for(int j=0;j<getColumns();j++){

sum.mat[i][j] = mat[i][j] + x;

}

}

return sum;

}

now I need an operator like this

int main(){

matrix a,b;

.

.

.

a = 2 + b;

.

.

return 0;

}

where the '2' is on the left side of the '+' sign how do I do it????

I allready have an operator for '+', one as described above and another for adding to class memebrs. like this

matrix matrix::operator +(matrix &m){

if(!((this->getColumns() == m.getColumns()) && (this->getRows() == m.getRows()))){

return *this;

}

matrix sum(m.iRows,m.iColumns);

for(int i=0;i<m.getRows();i++){

for(int j=0;j<m.getColumns();j++){

sum.mat[i][j] = mat[i][j] + m.mat[i][j];

}

}

return sum;

}

so how do I make the '2' add to the matrix???

10x

just the prototype will do!!!