Link to home
Start Free TrialLog in
Avatar of orenisraeli2000
orenisraeli2000

asked on

operators and stuff

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!!!
ASKER CERTIFIED SOLUTION
Avatar of kulpem
kulpem

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of orenisraeli2000
orenisraeli2000

ASKER

10x, I see your point