实例变量声明错误?

时间:2012-05-06 10:09:58

标签: objective-c

我的实例变量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;
}

1 个答案:

答案 0 :(得分:1)

你忘记了;在每一行的末尾

@interface NumberSub: NSObject

{
    int firstNumber;
    int secondNumber;
    int result ;
}