关于objective-c中方法调用的问题 10

代码如下:1-定义XYPoint接口文件#import<Foundation/Foundation.h>@interfaceXYpoint:NSObject@proper... 代码如下:
1-定义XYPoint接口文件#import <Foundation/Foundation.h>
@interface XYpoint : NSObject
@property int x,y;
-(void) setX:(int)xVal andY:(int) yVal;
@end

2-XYpoint实现代码
#import "XYpoint.h"
@implementation XYpoint
@synthesize x,y;
-(void) setX:(int)xVal andY:(int)yVal
{
x = xVal;
y = yVal;
}
@end

3-rectangl类接口代码
#import <Foundation/Foundation.h>
@class XYpoint;
@interface Rectangl : NSObject
@property int width,height;

-(XYpoint *) origin;
-(void) setOrigin:(XYpoint *) pt;
-(void) setWidth:(int)w andHeight:(int)y;
-(int) area;
-(int) perimeter;
@end

4-rectangl实现代码
#import "Rectangl.h"
#import "XYpoint.h"
@implementation Rectangl
{
XYpoint *origin;
}
@synthesize width,height;
-(void) setWidth:(int)w andHeight:(int)y
{
width = w;
height = y;
}
-(void) setOrigin:(XYpoint *)pt
{
origin = pt;
}
-(int) area
{
return width*height;
}
-(int) perimeter
{
return (width+height)*2;
}
-(XYpoint *) origin
{
return origin;
}
@end

5-主函数
#import <Foundation/Foundation.h>
#import "XYpoint.h"
#import "Rectangl.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {
Rectangl *myrect = [[Rectangl alloc]init];
XYpoint *myPoint = [[XYpoint alloc]init];

[myPoint setX:100 andY:200];
[myrect setWidth:5 andHeight:8];

//myrect.origin = myPoint;
[myrect setOrigin:myPoint];

//NSLog(@"myrect width = %i,height = %i",myrect.width,myrect.height);
NSLog(@"myrect width = %i,height = %i",[myrect width],myrect.height);
NSLog(@"origin at (%i,%i)",myrect.origin.x,myrect.origin.y); //注释[1]
NSLog(@"area = %i,perimeter = %i",[myrect area],[myrect perimeter]);
}
return 0;
}

1、在以上代码中,rectangle的实现代码里面并没有将origin作为@property的成员,因此手写了setOrigin和origin方法,merest.origin=mypoint中,origin是-(void) origin方法还是成员变量?并且为什么在使用myrect.origin=mypoint时却自动调用了setOrigin和origin方法?
2、在rectangle实现代码中,{XYpoint *origin}是将origin当成rectangle的成员变量了吗?或者说将origin作为rectangle的属性?
展开
 我来答
匿名用户
2016-06-26
展开全部
viewController*b1=[[viewControlleralloc]init];[self.navigationControllerpushViewController:b1animated:YES];[b1release]。
追问
本人初学者,能说的明白点吗?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式