以下代码给出了一个错误:“BankAccount没有可见的@interface声明选择器getAccountNumber” 为什么?请帮忙
// BankAccount.h
#import <Foundation/Foundation.h>
@interface BankAccount: NSObject
@property long accountNumber;
@end
// BankAccount.m
#import "BankAccount.h"
@implementation BankAccount
@end
//main.m
#import <Foundation/Foundation.h>
#import "BankAccount.h"
int main (int argc, const char * argv[]) {
BankAccount *account1 = [[BankAccount alloc] init];
[account1 setAccountNumber: 34543212];
NSLog(@" Account No = %li", [account1 getAccountNumber]);
return 0;
}
答案 0 :(得分:3)
生成的getter为accountNumber
,而不是getAccountNumber
。
答案 1 :(得分:1)
将[account1 getAccountNumber]
更改为[account1 accountNumber]
。