Re: method confusion
Re: method confusion
- Subject: Re: method confusion
- From: Charles Steinman <email@hidden>
- Date: Mon, 17 Sep 2007 14:43:50 -0700 (PDT)
--- Hans van der Meer <email@hidden> wrote:
> In my code I have in a testcase:
> @interface HMCharacterAlphabetTest : SenTestCase {
> ...
> Inside one of the tests:
> HMCharacterAlphabet *alphabet =
> [[HMCharacterAlphabet alloc]
> initWithSize: 3];
> defined in class HMCharacterAlphabet as:
> - (id) initWithSize: (unsigned) size; // class in
> HMCharacterAlphabet.h
>
> Somehow arises confusion with the identically typed
> init in NSImage.h:
> - (id)initWithSize:(NSSize)aSize;
> [SNIP]
> I fail to see why this is possible, as these
> declarations are in
> different classes.
But the compiler can't tell which class the method is
being sent to. The alloc method has a return type of
id, which could be anything. So when you send
initWithSize: to the result of alloc, the compiler
doesn't know what class it's talking to. I would
change the method name to something that doesn't
conflict, but if you have to keep it the same, you can
statically type it as [(HMCharacterAlphabet
*)[HMCharacterAlphabet alloc] initWithSize: 3]. This
will give the compiler the information it needs to use
the right method signature.
Cheers,
Chuck
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden