2012-05-06 285 views
0

我的實例變量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

「解析問題的結束:預期‘;’在聲明清單末尾「是一個非常明確的聲明;) – MJB

回答

1

申報清單的最後,你忘了,在每個線

@interface NumberSub: NSObject 

{ 
    int firstNumber; 
    int secondNumber; 
    int result ; 
} 
+0

哇,這很簡單,謝謝! – DanielPincus

+1

不要忘記接受答案,點擊小支票標誌:) –

+0

好吧,是否給你加分或者其他的東西? – DanielPincus