Re: multiple declarations for method `length' ?
Re: multiple declarations for method `length' ?
- Subject: Re: multiple declarations for method `length' ?
- From: glenn andreas <email@hidden>
- Date: Thu, 30 Dec 2004 21:23:28 -0600
On Dec 30, 2004, at 12:57 PM, Charlton Wilbur wrote:
If you check NSDictionary you'll find that:
- (id)objectForKey:(id)aKey
...it returns an "id" object. In other words, the compiler don't
know what type of object it is. When you call the method "length" on
that object, the compiler needs to guess what implementation to use.
If there is only one such method it's easy, but if there are several
it's not. You can help the compiler by casting [...]
I thought one of the huge advantages of message-passing over function
calls was that you could send messages to "id" objects and objc_send
would sort out the details.
Yes, which is why it works. But the compiler, which is issuing the
warning, can't necessarily tell what value will receive the message at
runtime, and so it's warning you that there are two possible methods
that might be invoked depending on what class the object is. If you
want to get rid of the warning, you can make your intent clear to the
compiler by inserting a cast.
Charlton
More importantly in this case is that there are two different
lengths - one in NSString (and NSData, etc...) which returns an
unsigned int, and another in NSStatusItem that returns a float.
It's the fact that there are multiple routines that return different
types that the warning happens - if not for the existence of
NSStatusItem, there wouldn't be a warning at all, since things like
NSString and NSData's length would all return their values in the same
(integer) register. The float, however, is returned in a floating
point register (and if the reciever were actually an NSStatusItem, the
return value would be whatever random values are in that integer
register).
Glenn Andreas email@hidden
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden