// 对象作为函数的参数--类与对象的内存分析
//成员方法和函数的区别
#import <Foundation/Foundation.h>
@interface Car : NSObject{
@public
int wheel;
int speed;
}
-(void) run;
@end
@implementation Car
-(void)run{
NSLog(@"%i轮子,时速%i的车子跑起来了",wheel,speed);
}
@end
//函数一:这种情况,c->wheel的值传进来了,并不会影响对象成员变量的值
void test(int m,int s){
m=20;
s=300;
}
//函数二:这种情况能够改变对象的值
void test1(Car* mc){
mc->wheel=5;
}
//函数三:这种情况不会改变
void test2(Car* mc){
Car *c2 = [Car new];
c2->wheel = 5;
c2->speed = 300;
mc = c2;
mc->wheel = 6;
}
int main(int argc, const char * argv[]) {
Car* c=[Car new];
c->wheel=4;
c->speed=200;
// test(c->wheel,c->speed);
test1(c);
[c run];
return 0;
}