简体   繁体   中英

Objective-C on GNUStep: Accessing ivars of the parent class

I'm pretty new to Objective-C. Most of my experience is in Java. I have a base class:

@interface Bug : NSObject <BugProtocol> {

    @private
    World* world;
    NSString* name;
    NSString* layer;
    long x;
    long y;
    BOOL alive;

...
...


}

...
...

@end

and a class that extends this base class:

@interface RandomBug : Bug
    ...
    ...
@end

However, when I try to access properties that I've defined in the parent class, the compiler complains that it cannot find them. Most of the examples I've seen for access properties is tailored towards OS X (ie, using things like @property which, as far as I know, is not fully supported in GNUStep).

I figured it out. I just need to use @protected (just like in Java):

@interface Bug : NSObject <BugProtocol> {

    @protected
    World* world;
    NSString* name;
    NSString* layer;
    long x;
    long y;
    BOOL alive;

...
...


}

...
...

@end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM