本帖最后由 bubuatt 于 2014-4-18 17:09 编辑
父类person中定义了方法- + (id)person
- {
- return [[[self alloc] init] autorelease];
- }
- + (id)personWithAge:(int)age
- {
- Person *p = [self person];
- p.age = age;
- return p;
- }
复制代码
子类在调用时
- int main(int argc, const char * argv[])
- {
- @autoreleasepool {
- GoodPerson *p = [GoodPerson personWithAge:10];
- p.money = 100;
- }
-
- return 0;
-
-
- }
复制代码
- Person *p = [self person];
复制代码
这句为什么不用GoodPerson *p = [self person];(这句会报错) |