0
我有两个属性,我宣布我的头文件,并在我的课合成(叫什么名字?)文件:错误:没有财产申报
- 宽度
高度
(散/磅符号)导入
@interface Rectangle : NSObject { int width; int height; } @property width, height; -(int) area; -(int) perimeter; -(void) setWidth: (int) w setHeight: (int) h; @end
.m文件:
(hash/pound symbol)import "Rectangle.h"
@implementation Rectangle
@synthesize width, height;
-(void) setWidth: (int) w setHeight: (int) h
{
width = w;
height = h;
}
-(int) area
{
return width * height;
}
-(int) perimeter
{
return (width + height) * 2;
}
@end
不过,我得到一些错误:
error: syntax error before 'width; error: no declaration of property 'width' found in the interface; error: no declaration of property 'height' found in the interface;
请原谅我有以“#”符号和代码格式问题的格式。
这工作,谢谢!我必须等待接受答案。 – redconservatory 2011-01-13 18:57:13