关于myrect.origin=mypoint中调用setOrigin的问题
来源:互联网 发布:mac win7 编辑:程序博客网 时间:2024/05/21 21:34
代码如下:
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方法,但是为什么在后面使用myrect.origin=mypoint时却自动调用了setOrigin和origin方法?
2、在rectangle实现代码中,{XYpoint *origin}是将origin当成rectangle的成员变量了吗?或者说将origin作为rectangle的属性?
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方法,但是为什么在后面使用myrect.origin=mypoint时却自动调用了setOrigin和origin方法?
2、在rectangle实现代码中,{XYpoint *origin}是将origin当成rectangle的成员变量了吗?或者说将origin作为rectangle的属性?
0 0
- 关于myrect.origin=mypoint中调用setOrigin的问题
- 关于Access Control Allow Origin错误的问题
- iOS中关于bounds、size、origin的区别
- 关于JSP中调用css的问题
- JS中关于函数调用的问题
- 关于c# 中调用webapi 的问题
- origin的FFT有问题?
- 设计一个名为MyPoint的类
- 关于SQL SERVER中系统函数调用的问题
- 继承中关于调用构造方法的问题
- 关于在perl中调用awk的问题
- java中关于构造函数内部调用自己的问题
- 关于OpenCV中矩阵调用自带函数的问题
- 关于WinRT中c++和c#相互调用的问题
- 关于VC中LineDDA函数的调用问题
- 关于在manageBean中调用业务方法的问题
- 关于WinRT中c++和c#相互调用的问题
- 关于ListView中getView被重复调用的问题
- HBASE内存泄露读文件失败的问题
- webService教程--深入webservice和发布webservice
- 蓝牙解析(part5):BLE的广播通信
- Bootstrap3 表单-水平排列的表单组的尺寸
- 精通 CSS+DIV 网页样式与布局 154
- 关于myrect.origin=mypoint中调用setOrigin的问题
- Mybatis报错Could not find parameter map java.util.Map
- 浅显解释 I/O阻塞 poll epoll
- Android杂谈(20)DrawerLayout实践
- 机器视觉算法 笔记
- maven编译过程中遇的相关问题
- webView中拿到选取的文字
- Redis安装
- 精通 CSS+DIV 网页样式与布局 155