Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: error: duplicate member ‘foo‘
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error: duplicate member ‘foo‘



Andreas did use @private -- that's why he was puzzled.  I suspect it's not allowed because it would break introspection and KVC.

--Andy

On Sep 9, 2009, at 10:21 AM, Steven Degutis wrote:

Andreas,

In Objective-C, instance variables (ivars) are declared as protected by default (I believe). This means they can be accessed from subclasses, as well as that class, but not outside the class. To make them inaccessible to subclasses, make them private using @private. Then this error will go away.


---------- Forwarded message ----------
From: Andreas Grosam <email@hidden>
Date: Wed, Sep 9, 2009 at 6:30 AM
Subject: error: duplicate member ‘foo‘
To: email@hidden


Hello,

I get the error "duplicate member 'foo', when I declare an ivar in a derived class whose name is the same as in the base class:


// Interface File Base.h
@interface Base : NSObject {
@private
   id              foo;
}
@end


// Interface File Derived.h
#import "Base.h"
@interface Derived : Base {
@private
   id              foo;
}
@end



Why I'm getting this error? I thought, this should be possible since the ivars shall only be visible in methods which are defined in the same class. So, there should never be a conflict.





Furthermore, I would expect that the following code will work as expected:

// Implementation file Base.m

@interface Base ()
@property (nonatomic, retain) id foo;
@end
@implementation Base
@synthesize foo;
@end

-(void) bar
{
   id o = self.foo;   // returns base->foo
}


// Implementation file Derived.m

@interface Derived ()
@property (nonatomic, retain) id foo;
@end
@implementation Derived
@synthesize foo;
@end

-(void) fooBar
{
   id o = self.foo;  // returns derived->foo
}





Thanks for a brief explanation.




Regards
Andreas

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >error: duplicate member ‘foo‘ (From: Andreas Grosam <email@hidden>)
 >Re: error: duplicate member ‘foo‘ (From: Steven Degutis <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.