开发者

Undeclared variable from base class when derived class has property

I have the following code below, where a 开发者_开发问答base class has a member which is (should be) accessible by a derived class.

The code below however gives a compilation error

...abcAppDelegate.m:30: error: 'baseVal_' undeclared (first use in this function)

If I call the variable using self->baseVal_ or if I remove the property defined in the derived class then everything is ok.

Also, if I define a category of the derived class, then I can access baseVal_ without error.

//---------------------------------------------------------------
// BASE CLASS
//---------------------------------------------------------------

@interface BaseClass : NSObject 
{
@protected    
    BOOL baseVal_;
} 
@end

@implementation BaseClass 
@end

//---------------------------------------------------------------
// DERIVED CLASS
//---------------------------------------------------------------

@interface DerivedClass : BaseClass {
} 
@property (readwrite) BOOL val;
@end

@implementation DerivedClass
@synthesize val;
- (void) foo {
    baseVal_ = YES;
}
@end


Have a look here: Click. Seems to possibly be a bug with GCC, but it's easily fixable by adding val as an instance variable instead of using the property without.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜