2012-01-08 9 views
0

に無効な引数型 'NSString *'があります。識別子エラーを解決した後、次のエラーが発生しましたが、私はどこに間違っているのかわかりません...エラー:セマンティック問題:単項式

私が学んだことで、これはうまくいくはずですが、代わりにエラーが発生します。奇妙なことは、私が見たすべての例が違うのですか?それでは、関数を使う正しい方法はありますか?

次Student.hファイルで見つかった

エラー:セマンティック問題:問題解析:予想される表現

無効な引数の型 'NSStringの*' エラー

表現単項へ私は、限られた経験で、コーディングにはまったく新しいので、これを解決するためのアドバイスをいただければ幸いです...そして、学習曲線...

のおかげ

Student.h(次のようになります)

#import <Foundation/Foundation.h> 

@interface Student : NSObject { 
@private 

NSString *name; 
NSString *gender; 
NSString *getStudentCategory; 
int age; 
} 
@property (nonatomic,retain) NSString *name; 
@property (nonatomic,retain) NSString *gender; 
@property (nonatomic) int age; 

- (NSString *)getStudentCategory; 

@end 

Student.m(次のようになります)

#import <Foundation/Foundation.h> 
#import "Student.h" 

@implementation Student 
@synthesize name,gender,age; 

- (id)init 
{ 
self = [super init]; 
if (self) { 

    - (NSString *)getStudentCategory //*ERROR: Semantic Issue: Invalid argument type 'NSString *' to unary expression* 
    { 
     NSString *studentCategory; 
    if (age <=12) 
     studentCategory = @"Primary School Student."; 
    else if (age >=13 && age <=17)   //*Error: Parse Issue: Expected expression* 
     studentCategory = @"Secondary School Student."; 
    else if (age >=18)      //*Error: Parse Issue: Expected expression* 
     studentCategory = @"College Student."; 
    } 
return self; 
} 

@end 

main.m(次のようになります)

#import <Foundation/Foundation.h> 
#import "Student.h" 

int main (int argc, const char * argv[]) 
{ 
@autoreleasepool { 

    Student *pupil =[[Student alloc] init]; 

     pupil.name = @"john"; 
     pupil.gender = @"male"; 
     pupil.age = 20; 

     NSLog([NSString stringWithFormat:@"Name: %@, Gender: %@, age %d",pupil.name,pupil.gender,pupil.age]); 

     NSLog([pupil getStudentCategory]); 

    } 
return 0; 

} 

私はStudent.mから削除しました:

- (id)init 
{ 
self = [super init]; 
if (self) 

それは機能しましたか?どうして? :/

アイデア? :-)

+0

'.m'ファイルの' getStudentCategory'メソッド内にコードがありますか?より多くの情報が役立ちます。 – jtbandes

+0

更新された情報... – pst007x

答えて

0

コンパイラからのエラーメッセージは、宣言されていない識別子が何であるかを示します。 「NSString」は宣言されていないと伝えられていますか?その場合は、使用する前に<Foundation/Foundation.h>または<Cocoa/Cocoa.h>をインポートしていることを確認してください。

+0

私のStudent.mのトップにあります:#import #import "Student.h"ありがとう – pst007x

+0

'getStudentCategory'に未確認IDENTIFIERを使用 – pst007x

+0

更新された情報.. – pst007x

1

さて、ここで問題です:

- (id)init 
{ 
self = [super init]; 
if (self) { 
    // WHAT IS THIS CHICANERY?! 
    - (NSString *)getStudentCategory //*ERROR: Semantic Issue: Invalid argument type 'NSString *' to unary expression* 
    { 
     NSString *studentCategory; 
    if (age <=12) 
     studentCategory = @"Primary School Student."; 
    else if (age >=13 && age <=17)   //*Error: Parse Issue: Expected expression* 
     studentCategory = @"Secondary School Student."; 
    else if (age >=18)      //*Error: Parse Issue: Expected expression* 
     studentCategory = @"College Student."; 
    } 
return self; 
} 

私は- (NSString *)getStudentCategoryから始まる行があるかわかりません。別のメソッドの中にメソッドを定義しようとしているように見えますが、それを行うことはできません。

+0

私の理解には関数: - (NSString *)getStudentCategory {//関数の定義をgetStudentCategory}関数を定義しようとしています... mmmm? : -/ – pst007x

+0

@ pst007x:別のメソッド(または関数)内でメソッド(または関数)を定義することはできません。 – mipadi

+0

- (NSString *)getStudentCategory { //機能コード } //これは同じエラーを生成しますか? – pst007x