我的實例變量secondNumber沒有聲明自己。爲什麼不? (我是編程新手,請耐心等待。) 在Xcode中,錯誤提示「解析問題:期望」;「 。在實例變量聲明錯誤?
// main.m
// Subtraction
//
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NumberSub: NSObject
{
int firstNumber
int secondNumber
int result
}
-(void) print;
-(void) setFirstNumber: (int) f;
-(void) setSecondNumber: (int) s;
-(void) resetAll;
-(void) printResult;
@end
@implementation NumberSub
-(void) setFirstNumber: (int) f;
{
firstNumber = f;
}
-(void) setSecondNumber: (int) s
{
secondNumber = s;
}
-(void) print
{
NSLog(@"%i - %i = ", firstNumber, secondNumber);
}
-(void) printResult
{
NSLog(@"%i", firstNumber - secondNumber);
}
-(void) resetAll
{
firstNumber = 0;
secondNumber = 0;
}
@end
int main (int argc, char *argv[])
{
NumberSub *subtractNumber = [[NumberSub = alloc]init];
[subtractNumber setFirstNumber: 10];
[subtractNumber setSecondNumber: 5];
[subtractNumber print];
[subtractNumber printResult];
[subtractNumber release];
return 0;
}
「解析問題的結束:預期‘;’在聲明清單末尾「是一個非常明確的聲明;) – MJB