Thread: compiling error
View Single Post
Old Nov 4th, 2006, 1:53 AM   #48
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
I am overloading the operator* to perform the intersection of 2 rectangle.
The function works well in the sense that it finds the intersection.
However, when printing, the program does not display the rectangle corresponding the left operand.
My function is set up like this:
 Rectangle Rectangle:: operator*(const Rectangle& r2)
     {
          Rectangle result;
          
          int xi,yi;// coordinate of upper left point intersection of 2 rectangles
          int urx,lry;//oordinate of lower right point intersection of 2 rectangles
          
          if( upLeft.getX()> r2.getX() )
              xi=upLeft.getX();
          else
              xi=r2.getX();
     
           if( upLeft.getY() > r2.getY() )
              yi=upLeft.getY();
          else
              yi=r2.getY();      
              
          if(  (upLeft.getX()+width ) <  (upLeft.getX()+r2.getWidth() )  )
               urx= upLeft.getX()+width;
          else
               urx=upLeft.getX()+r2.getWidth();
               
          if(  (upLeft.getY()+height ) <  (r2.getY()+r2.getHeight() )  )
               lry= upLeft.getY()+height;
          else
               lry=r2.getY()+r2.getHeight();     
           upLeft.setPoint(xi,yi);   
           width=urx-xi;  
           if(width<0)
              width=0;
           height=lry-yi;
           if(height<0)
              height=0;
              result.set(upLeft,width,height,'*');
              return result;
     }
So when I called the function
rectar[5]=rectar[3]*rectar[4];
    rectar[5].setPaint('5');

it does not display r3 but display r5 and r4.
why is that?
brad sue is offline   Reply With Quote