我是 Objective-C 的新手,不完全确定我哪里出错了。我试图让程序打印正方形的面积和周长。程序告诉我,我正在向周界和区域方法发送一个未声明的标识符
#import <Foundation/Foundation.h>
@interface Rectangle : NSObject
{
int width;
int height;
}
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(int) width;
-(int) height;
-(int) area;
-(int) perimeter;
@end
@implementation Rectangle
-(void) setWidth:(int)w
{
width = w;
}
-(void) setHeight: (int)h
{
height = h;
}
-(int) width
{
return width;
}
-(int) height
{
return height;
}
-(int) area
{
return width*height;
}
-(int) perimeter
{
return (2*width + 2*height);
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Rectangle *rect1 = [[Rectangle alloc] init];
[rect1 setWidth:2];
[rect1 setHeight:7];
NSLog(@"The perimeter of rect1 is: %i and the area is: %i", area, area);
}
return 0;
}