Re: compiler assumes pointer, but its a float
Re: compiler assumes pointer, but its a float
- Subject: Re: compiler assumes pointer, but its a float
- From: Jeff Disher <email@hidden>
- Date: Thu, 5 Dec 2002 04:50:32 -0500
There are a few ways around this problem:
1) down-cast the instance to a class that understands this message.
This will solve the problem but casting looks ugly and doesn't feel
write in true OOP
2) have the call occur in a method that accepts an instance of the
type that you expect it to be. This works but requires writing a
method to do that and you may get warnings about passing an arg with
from incompatible pointer type.
3) implement that method in the abstract base-class and have it call
"[self doesNotRespondToSelector:_cmd]" (I think that is the right
method, I don't have my code in front of me right now). This will
allow you to send message to what the compiler thinks is an instance of
the base class. If it actually is an instance of the base class, you
will get an exception at run-time, otherwise, it will work. This is
analogous to the C++ concept of an abstract method (void method() =
0;). This is usually preferable but can seem odd if none of the other
sub-classes override this method.
Hope those ideas help,
Jeff.
On Thursday, December 5, 2002, at 12:02 AM, crucial felix wrote:
Hi,
I'm translating some stuff from a smalltalk implementation.
I have AbstractPlayer and APlayer (subclass)
I have AbstractPlayerView and APlayerView (subclass)
each player class has a view class, and the view classes inherit
useful things from each other.
the abstract class has a variable
AbstractPlayer *model;
APlayer has a method which returns a float
-(float)pchRatio;
the problem:
in the APlayerView i attempt to get the pchRatio
[pchRatioSlider setFloatValue: (float)[model pchRatio]];
but the compiler complains:
APlayerView.m:33: warning: `AbstractPlayer' does not respond to
`pchRatio'
APlayerView.m:33: pointer value used where a floating point value was
expected
i tried including APlayer.h, but there's no way to tell it that its
really going to get a float.
Jeff Disher
President and Lead Developer of Spectral Class
Spectral Class: Shedding Light on Innovation
http://www.spectralclass.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.