您的位置:首页 > 移动开发 > Objective-C

OC匿名对象

2015-11-19 23:00 471 查看
#import <Foundation/Foundation.h>

@interface Car : NSObject
{
@public
int speed;
}
- (void)run;
@end

@implementation Car
- (void)run{
NSLog(@"速度为%d的车子跑起来了",speed);
}

@end

int main()
{

//不要写类似匿名对象这样的代码//造成内存泄露
[Car new]->speed = 300;
//匿名方法//上下两个[Car new]都不一样
[[Car new] run];
//每次[Car new]调用都会创建一个新对象

//    Car *c;
//    c = [Car new];
//    c->speed = 250;
//
//    [c run];
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Objective-C