The @class Directive
Now you can work with rectangles (and squares as well!) with the ability to set their widths, heights, and origins. First, let’s take a complete look at your Rectangle.h interface file:
#import <Foundation/Foundation.h>@class XYPoint;@interface Rectangle: NSObject@property int width, height;-(XYPoint *) origin;-(void) setOrigin: (XYPoint *) pt;-(void) setWidth: (int) w andHeight: (int) h;-(int) area;-(int) perimeter;@end
You used a new directive in the Rectangle.h header file:
@class XYPoint;
You needed this because the compiler needs to know what an XYPoint is when it encounters it as one of the instance variables defined for a Rectangle. The class name is also used in the argument and return type declarations for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access