self super

来源:互联网 发布:苏曼莎脸型数据 编辑:程序博客网 时间:2024/05/01 04:33

self

相当于this,它的值可改变,
当一个方法调用同类中的另一个方法时,self不可省略

super

和self指向相同的receiver,但super是要到父类方法列表找对应方法,
只是编译器指示符,不能赋值,而self可以赋值(例如对象的初始化)

//复数相加complex.h-(Complex*)add:(Complex*)a{    Complex* c = [[Complex alloc] init];    c.real = real + a.real;    c.imag = imag + a.imag;    return [c autorelease];}main.mComplex* c1 = [[Complex alloc]initWithReal:2.1 imag:1.2];Complex* c2 = [[Complex alloc]initWithReal:2.3 imag:3.6];Complex *c = [c1 add:c2];NSLog(@"%g+%gi",c.real,c.imag);
0 0
原创粉丝点击