2011-01-25 18 views
4

Objective-cについてもう少し勉強しようとしています。私は4つのエラー、すべて同じです。 "関数の暗黙の宣言"、私はそれを見つけたが、私は解決策を見つけることができませんでした。目的関数cの暗黙の宣言に伴う問題

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()) { 

すべては、事前に

ありがとう "機能の暗黙の宣言" を言いますダイエッガー

答えて

2

私はそれがCとObjective Cの構文を混同している可能性があると思います。

試してみてください。

if (newFrequency > [self maxFMFrequency]) 
+0

の下に与えられたとして、関数呼び出しを変更することでソートこれは、バイナリに無効なオペランドを返した> –

+0

うーん...多分マークまたはtheChrisは理由として私たちを啓発することができます。それは私からの投票の価値があるでしょう! – Dave

+4

問題は、上記のようにメソッドがインスタンスメソッドであるかのようにメソッドにアクセスすると、ポインタが返され、コンパイラはバイナリ操作を実行することを前提としています。 >はバイナリ演算子ではないので、そのエラーをスローします。私はあなたの努力に感謝しますが、上記のコメントのOPで述べたようにこの答えは正しいわけではありません。あなたの幸運な日でなければならない! :) – theChrisKent

3

あなたはメソッドや関数を混同しています。

あなたは

if (newFrequency > maxFMFrequency()) { 

を期待C関数として実装

double maxFMFrequency() 

のような関数の宣言を見るために事を呼び出すコード - これはからデータを取得することができなくなりますオブジェクトなので、メトフを使用する必要があります

ヘッダーはメソッドを宣言しています

+(double)maxFMFrequency; 

いますが、次のようにそれらのそれぞれを変更する必要がありますので、

if (newFrequency > [RadioStation maxFMFrequency]) 
9

これらはクラスメソッドですと呼ばれる必要がある:

if (newFrequency > [RadioStation maxFMFrequency]) { 
if (newFrequency < [RadioStation minFMFrequency]) { 
if (newFrequency > [RadioStation maxAMFrequency]) { 
if (newFrequency < [RadioStation minAMFrequency]) { 
+0

Thx、これは私のprolemの解決策でした –

+2

もしこれが受け入れられた答えとしていれば、それはうまくいきません。 – Mark

+1

「インスタンスメソッド」ではなく「クラスメソッド」になりますか? – Dave

1

私は同じ問題に直面しました。

//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]]; 
} 
関連する問題