当前位置: 代码迷 >> Iphone >> OC - 函数的调用
  详细解决方案

OC - 函数的调用

热度:227   发布时间:2016-04-25 05:36:32.0
OC -- 函数的调用

 

@interface Car : NSObject{

    @public

    int _wheels;

    int _speed;

}

 

- (void)run;

 

@end

 

@implementation Car

 

- (void)run{

    NSLog(@"%d个轮子, 速度为%d的车子跑起来了", _wheels, _speed);

}

 

@end

 

void test1(Car *newCar){

    newCar->_wheels = 5;

}

 

void test2(Car *newCar);

 

int main(int argc, const char * argv[]) {

    

    Car *c1 = [[Car alloc] init];

    Car *c2 = [[Car alloc] init];

    test1(c1);

    test2(c2);

    [c1 run];

    [c2 run];

    

    return 0;

}

 

void test2(Car *newCar){

    newCar->_wheels = 4;

    newCar->_speed = 300;

}

 

  相关解决方案