我了解关键字“va_list”“va_start”“va_arg”“va_end”的用法。我的晚餐班有一个 init 方法,如下所示:
超级班:
- (id) initWithChildren:(NSObject*)firstChild, ... NS_REQUIRES_NIL_TERMINATION{
if(self = [super init]){
va_list children;
va_start(children, firstChild);
self.children = [[NSMutableArray alloc] initWithObjects:firstChild, nil];
firstChild.father = self;
NSObject* child;
while ((child = va_arg(children, NSObject*)) != nil){
[_children addObject:child];
}
va_end(children);
}
return self;
}
它运作良好。但我很难继承它。
子类
- (id) initWithName:(NSString*)name children:(NSObject*)firstChild, ... NS_REQUIRES_NIL_TERMINATION{
self = [super initWithChildren:"what should I write here?"];
if (self){
self.name = name;
//other subclass work
}
return self;
}
有什么想法吗?谢谢。