• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
multiple declarations for method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: multiple declarations for method
      • From: "Erik M. Buck" <email@hidden>
  • Prev by Date: Re: 'small' attribute of NSPopUpButton
  • Next by Date: Re: App and custom icon.
  • Previous by thread: Re: theoretical idea - would this work?
  • Next by thread: Re: multiple declarations for method
  • Index(es):
    • Date
    • Thread