Objective C 中函数隐式声明的问题
我试图更多地了解 Objective-c,但目前我陷入了困境。我有 4 个错误,都是一样的。 “函数的隐式声明”,我用谷歌搜索但没有找到解决方案。
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
这些行
if (newFrequency > maxFMFrequency()) {
if (newFrequency < minFMFrequency()) {
if (newFrequency > maxAMFrequency()) {
if (newFrequency < minAMFrequency()) {
都说“函数的隐式声明”
提前感谢, 迪格尔
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 lines
if (newFrequency > maxFMFrequency()) {
if (newFrequency < minFMFrequency()) {
if (newFrequency > maxAMFrequency()) {
if (newFrequency < minAMFrequency()) {
all say "Implicit declaration of function"
Thanx in advance,
Dietger
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些是类方法,因此您需要按如下方式更改它们:
These are class methods so you will need to change each of them as follows:
您混淆了方法和函数。
您调用该事物的代码
期望看到函数的声明,例如
作为 C 函数实现的函数 - 这将无法从对象获取数据,因此您需要使用标头
确实声明了一个方法的方法,
但需要被称为
You are mixing up methods and functions.
the code you call the thing with
expects to see a declaration of a function like
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
but needs to be called as
我认为这可能是因为你混合了 C 和 Objective C 语法。
尝试:
I think it might be because you're mixing C and Objective C syntax.
Try:
我遇到了同样的问题。通过修改函数调用进行排序,如下所示
I faced same problem. sorted by modifying the function call as given below