0

我的实例变量 secondNumber 没有声明自己。为什么不?(我是编程新手,所以请多多包涵。)在 Xcode 中,错误提示:“Parse Issue: Expected ';' 在声明列表的末尾。

//  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;
}
4

1 回答 1

1

你忘了 ; 在每行的末尾

@interface NumberSub: NSObject

{
    int firstNumber;
    int secondNumber;
    int result ;
}
于 2012-05-06T10:11:57.947 回答