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