Problem with implicit declaration of function in objective c
I trying to learn a bit more about Objective-c, and at the moment i'm stuck. I got 4 errors, all the same. "Implicit declaration of function", I googled it but i didn't find a solution.
RadioStation .h
#import <Cocoa/Cocoa.h>
@interface RadioStation : NSObject {
NSString* name;
double frequency;
char band;
}
+(double)minAMFrequency;
+(double)maxAMFrequency;
+(double)minFMFrequency;
+(double)maxFMFrequency;
-(id)initWithName:(NSString*)newName atFrequency:(double)newFrequency withBand:(char)newBand;
-(NSString*)name;
-(double)frequency;
-(char)band;
-(void)setName:(NSString*)newName;
-(void)setFrequency:(double)newFrequency;
-(void)setBand:(char)newBand;
@end
RadioStation .m
#import "RadioStation.h"
@implementation RadioStation
+(double)minAMFrequency{
return 520.0;
};
+(double)maxAMFrequency{
return 1610.0;
};
+(double)minFMFrequency{
return 88.3;
};
+(double)maxFMFrequency{
return 107.9;
};
-(id)initWithName:(NSString*)newName atFrequency:(double)newFrequency withBand:(char)newBand{
self = [super init];
if(self != nil){
name = [newName retain];
band = newBand;
if (band == 'F') {
if (newFrequency > maxFMFrequency()) {
frequency = maxFMFrequency();
}else if (newFrequency < minFMFrequency()) {
frequency = minFMFrequency();
}else {
frequency = newFrequency;
}
}else if (band == 'A') {
if (newFrequency > maxAMFrequency()) {
frequency = maxAMFrequency();
}else if (newFrequency < minAMFrequency()) {
frequency = minAMFrequency();
}else {
frequency = newFrequency;
}
}
}
return self;
}
@end
The l开发者_StackOverflow社区ines
if (newFrequency > maxFMFrequency()) {
if (newFrequency < minFMFrequency()) {
if (newFrequency > maxAMFrequency()) {
if (newFrequency < minAMFrequency()) {
all say "Implicit declaration of function"
Thanx in advance, Dietger
These are class methods so you will need to change each of them as follows:
if (newFrequency > [RadioStation maxFMFrequency]) {
if (newFrequency < [RadioStation minFMFrequency]) {
if (newFrequency > [RadioStation maxAMFrequency]) {
if (newFrequency < [RadioStation minAMFrequency]) {
You are mixing up methods and functions.
the code you call the thing with
if (newFrequency > maxFMFrequency()) {
expects to see a declaration of a function like
double maxFMFrequency()
implemented as a C function - this will not be able to get data from the object so you need to use a methof
the header does declare a method as
+(double)maxFMFrequency;
but needs to be called as
if (newFrequency > [RadioStation maxFMFrequency])
I think it might be because you're mixing C and Objective C syntax.
Try:
if (newFrequency > [self maxFMFrequency])
I faced same problem. sorted by modifying the function call as given below
//function declaration
-(void) downloadPage:(NSString *)url;
//function definition
-(void) downloadPage:(NSString *)url
{
userOutput.text = url;
}
//and now the fixed call to downloadPage
-(IBAction) onButtonOneClicked:(id) sender
{
userOutput.text = @"please wait...";
//fixed call to downloadPage
[self downloadPage:[userInput text]];
}
精彩评论