識別子エラーを解決した後、次のエラーが発生したと思いますが、どこが間違っているのかわかりません...
私が学んだことで、これはうまくいくはずです....しかし代わりにエラーを生成します..奇妙なことは私が出くわすすべての例が異なるということですか?では、関数を使用する正しい方法はありますか?
次の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)
そしてそれはうまくいきましたか?なぜ?:-/
何か案は?:-)