[comp.sys.next] float c=[sliderA floatValue] won't compile-why?

tholland@amy.skidmore.edu (06/22/91)

Given a slider called "sliderA",  I am tring to query it as to its current
float value.  Here's my code:

float c;
c = [sliderA floatValue];


This seems to work fine for one program, but for another it won't compile
and I get the following error:

"warning: cannot find method
 warning: return type for 'floatValue" defaults to id
 warning: incompatible types in assignment"

What's going wrong here ??  Suggestions ?

Thanks

Anthony Holland
Skidmore College
Saratoga Springs, NY

next mail: tholland@pars.skidmore.edu

eps@toaster.SFSU.EDU (Eric P. Scott) (06/23/91)

In article <1163.2862231f@amy.skidmore.edu> tholland@amy.skidmore.edu writes:
>c = [sliderA floatValue];

>"warning: cannot find method
> warning: return type for 'floatValue" defaults to id
> warning: incompatible types in assignment"
>
>What's going wrong here ??  Suggestions ?

You left out

#import <appkit/Slider.h>

Since sliderA is presumably an id (rather than a "static type"),
your code will still compile if you pull in ANYTHING with a
floatValue method.  But you really want to declare what you
use...

					-=EPS=-

wb1j+@andrew.cmu.edu (William M. Bumgarner) (06/24/91)

More likely than not, you haven't #imported the appropriate stuff:

At the top of your .h or .m file do:

#import <appkit/Slider.h> // this imports only the Slider class declration

or

#import <appkit/appkit.h> // this imports the whole bloody appkit--
slower, //but more convenient.  See the warning below.



---

You can use the #import <appkit/appkit.h> to make your life managing the
.h files easier, BUT, by doing this, you lose some of cc's ability to
figure things out.  As an example, if you have a Slider connected to an
outlet and send a message that Slider doesn't implement to that outlet
(but that some other class in the appkit does implement), then CC won't
find the problem but your App will crash.

I have found that by only including the classes that are neccessary, you
gain several advantages:

 - cc will bitch if you haven't done the Right Thing (usually... there
are certain cases where it won't)
 - You will have a much better understanding of exactly what classes are
used in your application
 - compile times will be faster because cc doesn't have to include everything.


hope this helps,
b.bum


b.bumgarner            | Disclaimer:  All opinions expressed are my own.
wb1j+@andrew.cmu.edu   | I officially don't represent anyone unless I
NeXT Campus Consultant | explicity say I am doing so. So there. <Thpppt!>
"I ride tandem with the random/Things don't run the way I planned them.."

aozer@next.com (Ali Ozer) (06/25/91)

In article <1163.2862231f@amy.skidmore.edu> tholland@amy.skidmore.edu writes:
>float c;
>c = [sliderA floatValue];
>
>... I get the following error:
>"warning: cannot find method
> warning: return type for 'floatValue" defaults to id
> warning: incompatible types in assignment"

Apparently the compiler could not find the method "floatValue" declared
anywhere, so it assumes the method returns id, and the assignment of 
id to float rightfully generates the warning.

In this case you should probably be importing <appkit/Control.h> or
<appkit/Slider.h>.

Ali, Ali_Ozer@NeXT.com