解決標識錯誤後,我想,我現在已經產生了以下錯誤,但我看不到的地方我已經錯了...錯誤:語義問題:無效的參數類型「的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)
它的工作?爲什麼? : -/
任何想法? :-)
你是否在'.m'文件中的getStudentCategory方法中有任何代碼?更多信息將有所幫助。 – jtbandes 2012-01-08 21:29:25
更新信息... – pst007x 2012-01-09 11:53:47