没有名字的对象称为匿名对象
举例:
# import <Foundation/Foundation.h>
@interface Car : NSObject
{
@public
int speed;
}
- (void)run;
@end
@implementation Car
- (void) run
{
NSLog(@"速度为%d的车子跑起来了",speed);
}
@end
int main()
{
//Car *c = [Car new];
//Car *c;
//c = [Car new];
//c->speed = 269;
[Car new] ->speed = 599;//不要这样写,从内存表管理的角度来看,是不对的,不要写匿名对象这样的代码,会造成内存泄露
[[Car new] run];//每次调用[Car new]都会生成新的对象
}
|
|