匿名对象oc

 

#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;

    c = [Car new];

    c->speed = 250;

    

    [c run];*/

    

    // 不要写类似匿名对象这样的代码

    // 只要求能说出输出结果

    [Car new]->speed = 300;

    

    [[Car new] run];

    

    //Car *c = [Car new];

    

    return 0;

}

posted @ 2016-03-28 10:30  lance.xiang  阅读(90)  评论(0)    收藏  举报