我是新來的客觀,只是試圖理解簡單的概念。 我已經閱讀Objective C for傻瓜和Mac OSX的可可編程(大部分)。 我試圖自己製作一個簡單的小程序,並意識到我知道的很少。我不斷收到"Use of Undeclared Identifier "calculateAge', did you mean 'Calculate' "
錯誤。使用未聲明的標識符'calculateAge'
任何人都可以告訴我下面的代碼有什麼問題,爲什麼? 預先感謝一堆。
#import <Foundation/Foundation.h>
@interface Calculate : NSObject
{
int myYear;
int nowYear;
}
- (int) calculateAge:(int)birthYear:(int)nowYear;
@end
@implementation Calculate
- (int) calculateAge:(int)birthYear:(int)nowYear// need myYear
{
NSLog(@"The birthYear is: %i\n", birthYear);
int myAge = nowYear - birthYear;
//NSLog(@"The nowYear is: %i\n", nowYear);
NSLog(@"The age is: %i\n", myAge);
return myAge;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"Hello, World!");
int myY = 1963;
int nowY = 2012;
int myYear = 1963;
int nowYear = 2012;
//int myAge = calculateAge:(int) birthYear: (int) nowYear;
int myAge = calculateAge:(int) myY: (int) nowY;
NSLog(@"The nowYear is: %i\n", nowYear);
NSLog(@"The age is: %i\n", myAge);
}
return 0;
}
@end
什麼編譯器說**完全**。 (我的意思是錯誤)。 – elyashiv
您是否需要將calculateAge信號發送到您的Calculate類的實例? –