我有一个基本的Rectangle类。我正在试图计算给定原点,宽度和高度的右上角。返回计算对象
我在我的main.m中设置原点,宽度和高度,我可以NSLog它们并获取正确的值。当我尝试在矩形上调用名为upperRight的Rectangle方法时,我得到0,0而不管投入。
下面是我使用的main.m行:Rectangle类的
NSLog(@"The upper right corner is at x=%f and y=%f", myRectangle.upperRight.x, myRectangle.upperRight.y);
下面是相关的(我认为):
@implementation Rectangle
{
XYPoint *origin;
XYPoint *originCopy;
XYPoint *upperRight;
}
@synthesize width, height;
-(XYPoint *) upperRight {
upperRight.x = origin.x + width;
upperRight.y = origin.y + height;
return upperRight;
}
即使我尝试设置upperRight。在方法中x = 200,我仍然获得0,0主返回。
我明显缺少一些基本的理解。
编辑:
下面是在主设定值:
Rectangle *myRectangle = [[Rectangle alloc]init];
XYPoint *myPoint = [[XYPoint alloc]init];
XYPoint *testPoint = [[XYPoint alloc]init];
//XYPoint *translateAmount = [[XYPoint alloc]init];
[myRectangle setWidth: 15 andHeight: 10.0];
[myPoint setX: 4 andY: 3];
这里的XYPoint.m:
#import "XYPoint.h"
@implementation XYPoint
@synthesize x, y;
-(void) setX:(float)xVal andY:(float)yVal {
x = xVal;
y = yVal;
}
@end
你可以显示当你做设置/通话? – Larme
@添加了本地信息 – tangobango