multiple declarations for method
multiple declarations for method
- Subject: multiple declarations for method
- From: Kim Foo-Jones <email@hidden>
- Date: Sat, 26 Jan 2002 18:28:00 +0000
I have a hierarchical data structure with objects of type A
containing objects of type B etc...
An object of type B would be initialised like this:
- (id) initWithParent:(TypeA*);
and type C objects:
- (id) initWithParent:(TypeB*);
However, the compiler gives "multiple declarations for method"
warnings and if it chooses to use the wrong one, it gives an
error:
// This is called by a TypeB object
TypeC* newObject = [[TypeC alloc] initWithParent: self];
I can circumvent the error by overriding +alloc and statically
typing the return value:
+ (TypeC*) alloc
{
return [super alloc];
}
Is this a reasonable thing to do? Is there a better way around
this? The other alternative I see is to typecast after the
allocation:
TypeC* newObject = [(TypeC*) [TypeC alloc] initWithParent: self];
But that's not as neat to my eyes...
I'm just wandering if there are any potential problems with the
overriding +alloc method?
Thanks,
-Kim