title: Pointers, Invalid Operands to Binary, and Noobs
body: <p>[Edit:  Rectangle definition added at bottom.]
  [Edit2:  XYPoint interface added at bottom.]</p>
  
  <p>I'm working on a method that checks if two rectangles overlap. (Yeah, I'm in Kochan's <em>Programming in Objective-C</em>, doing the exercises, and I am painfully new at this.)  When I compile this, the error message is: "Invalid operands to binary +". I get it on the first <em>if</em> statement and on the <em>if-else</em> that follows it.  </p>
  
  <p>I think I have an issue with pointers, but Kochan doesn't talk about this much. </p>
  
  <p>And, if I take out these lines, the rest of the method works just fine.  And the relevant variables are all floating type. </p>
  
  <p>Help? </p>
  
  <p>Also, any other thoughts on the method would be totally welcome. (Like, how do I make lines of code not go out so long. Like I said, painfully new at this.) </p>
  
  <pre><code>-(void) overlap: (Rectangle *)r2
  {
  
  overlapRectangle = [[Rectangle alloc] init];
  leftRectangle = [[Rectangle alloc] init];
  rightRectangle = [[Rectangle alloc] init];
  lowerRectangle = [[Rectangle alloc] init];
  upperRectangle = [[Rectangle alloc] init];
  
  BOOL xIntersect = NO;
  BOOL yIntersect = NO;
  
  
  //  Test to see if the Rectangle contains, or is equal to, Rectangle b
  
  if (origin.x &lt;= r2.origin.x &amp;&amp; origin.y &lt;= r2.origin.y &amp;&amp; (origin.x + width) &gt;= (r2.origin + r2.width) &amp;&amp; (origin.y + height) &gt;= (r2.origin.y + r2.height) ) 
  {
      overlapRectangle = r2;
  }
  
  //  Test to see if Retangle b contains, or is equal to, the Rectangle
  
  else if (origin.x &gt;= r2.origin.x &amp;&amp; origin.y &gt;= r2.origin.y &amp;&amp; origin.x + width &lt;= r2.origin + r2.width &amp;&amp; origin.y + height &lt;= r2.origin.y + r2.height ) 
  {
      overlapRectangle = self;
  }
  
  //  I should add tests for triangles overlapping on three 
  //  sides or overlapping  on two sides, but I'm not going 
  //  to right now. Just learning objects and methods.
  
  
  //  Test to see if rectangles overlap on the x-axis 
  //  Current is an if, because I wanted to run the code below
  //  to see if it worked, and it did. 
  
  if (origin.x &lt;= r2.origin.x)
  {
      leftRectangle = self;
      rightRectangle = r2;
  }
  else 
  {
      rightRectangle = self;
      leftRectangle = r2;
  }
  
  if (rightRectangle.origin.x + rightRectangle.width &gt; leftRectangle.origin.x) 
  {
      xIntersect = YES;
  }
  
  
  
  //  Test to see if rectangles overlap on the y-axis
  
  if (origin.y &lt;= r2.origin.y)
  {
      lowerRectangle = self;
      upperRectangle = r2;
  }
  else 
  {
      lowerRectangle = self;
      upperRectangle = r2;
  }
  
  if (lowerRectangle.origin.y + lowerRectangle.height &gt; upperRectangle.origin.y) 
  {
      yIntersect = YES;
  }
  
  
  
  //  If retangles overlap on both the x-axis and y-axis, 
  //  determination of overlapping rectangle's origin, height, and width
  //  and display same.
  
  if (xIntersect == YES &amp;&amp; yIntersect == YES) 
  {
      overlapRectangle.origin.y = upperRectangle.origin.y;
      overlapRectangle.origin.x = rightRectangle.origin.x;
      overlapRectangle.height = lowerRectangle.height - (upperRectangle.origin.y - lowerRectangle.origin.y);
      overlapRectangle.width = leftRectangle.width - (rightRectangle.origin.x - leftRectangle.origin.x);
  
  
      NSLog (@"Your rectangles overlap.");
      NSLog (@"Rectangle: w = %g, h = %g", overlapRectangle.width, overlapRectangle.height);
      NSLog (@"Area = %g, Perimeter = %g", [overlapRectangle area], [overlapRectangle perimeter]);
      NSLog (@"Origin at (%g, %g)", overlapRectangle.origin.x, overlapRectangle.origin.y);
  }
  
  else 
  {
      NSLog (@"Your rectangles do not overlap.");
  }
  
  
  
  [overlapRectangle autorelease];
  [leftRectangle autorelease];
  [rightRectangle autorelease];
  [lowerRectangle autorelease];
  [upperRectangle autorelease];
  
  }
  </code></pre>
  
  <p>Rectangle Definition: </p>
  
  <p>// Interface, Rectangle Class</p>
  
  <pre><code>@interface Rectangle : NSObject
  
  {
      float width;
      float height;
      XYPoint *origin;
  
      // For overlapping calculations
  
      Rectangle *overlapRectangle;
      Rectangle *leftRectangle; 
      Rectangle *rightRectangle; 
      Rectangle *lowerRectangle; 
      Rectangle *upperRectangle; 
  }
  
  @property float width, height;
  
  -(XYPoint *) origin;
  -(void) setOrigin: (XYPoint *) pt;
  -(void) setWidth: (float) w andHeight: (float) h;
  -(float) area;        
  -(float) perimeter;   
  -(void) print;
  -(void) translate;
  -(void) overlap: (Rectangle *)r2;
  -(void) draw;
  
  
  @end
  </code></pre>
  
  <p>XYPoint interface:  </p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @interface XYPoint : NSObject
  {
      float x;
      float y;
  }
  
  @property float x, y;
  
  -(void) setX: (float) xVal andY: (float) yVal;
  
  @end
  </code></pre>