我是客观的新手,只是想理解简单的概念。我已经阅读了 Objective C for dummy 和 Cocoa Programming for Mac OSX(大部分)。我试着自己做一个简单的小程序,发现我知道的很少。
我不断收到"Use of Undeclared Identifier "calculateAge', did you mean 'Calculate' "
错误。
谁能告诉我下面的代码有什么问题以及为什么?提前感谢一堆。
#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