Re: Sending the "value" message to an object typed "id"
Re: Sending the "value" message to an object typed "id"
- Subject: Re: Sending the "value" message to an object typed "id"
- From: Jens Alfke <email@hidden>
- Date: Mon, 7 Sep 2009 10:13:30 -0700
On Sep 7, 2009, at 5:11 AM, Graham Cox wrote:
I suspect what's occurring is that -value is defined in multiple
classes having different return types: maybe float in one case and
id in another, say. The compiler can't disambiguate a method based
on return type alone so compiles based solely on the first one it
encounters, which to all intents and purposes may as well be random.
It's a dirty little secret of Obj-C (or at least the current
compilers) and is a very real source of bugs (and sometimes quite
dangerous ones at that).
BTW, Paulo, this situation should have generated a compiler warning
saying that it can't tell which version of the 'value' message it
should use here. Whenever you get a warning like that, you should cast
the receiver to the appropriate class.
(This is yet another reason I recommend always enabling "treat
warnings as errors" when building Obj-C code.)
—Jens_______________________________________________
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