2

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
LK.
  • 4,499
  • 8
  • 38
  • 48
  • Looks like you are getting the error in your App Delegate, not the DerivedClass. Can you post the AppDelegate code where you are accessing this variable? – hundreth Jun 22 '11 at 18:56
  • just for the example here I have stuck the classes (the exact code as above) into the appDelegate.m file - but the example is taken from a larger codebase – LK. Jun 22 '11 at 18:57
  • BTW: Objective-C doesn't have member variables, but instance variables. – bbum Jun 22 '11 at 19:50

1 Answers1

0

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.

Community
  • 1
  • 1
thomashw
  • 956
  • 4
  • 7