开发者

Interesting loop? How can a base class include a child class as a member?

开发者 https://www.devze.com 2023-02-22 01:25 出处:网络
How can a base class include a child开发者_如何转开发 class as a member? For example: @interface Magic : NSObject {

How can a base class include a child开发者_如何转开发 class as a member? For example:

@interface Magic : NSObject {
@private
       NSString* name;
       int power;
       int manaCost;
       SpecialKindOfMagic* thisMuch;
}
@end

@interface SpecialKindOfMagic : Magic {
@private
       int thisMuchSpecial;
}
@end


Use a forward declaration before the declaration of the Magic class:

@class SpecialKindOfMagic;

@interface Magic ...

Also, it's very unusual to declare a class that doesn't descend from NSObject, so you probably meant to write:

@interface Magic : NSObject {
0

精彩评论

暂无评论...
验证码 换一张
取 消