#import <Foundation/Foundation.h>
@interface Caculator :NSObject
{
@public
int _num1;
int _num2;
float _result;
}
-(float)add:(int)num1 andnum2:(int) num2;
@end
@implementation Caculator
-(float)add:(int)num1 andnum2:(int) num2;
{
//这里可以用-result = num1+ num2,然后返回的时候可以用_result返回,为什么?
return num1+num2;
}
@end
float test(){
Caculator *cal = [Caculator new];
float result = [cal add:6 andnum2:2];
NSLog(@"num1+num2=%.2f",result);
return .3f;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
test();
}
return 0;
}
|
|