#import<Foundation/Foundation.h>
@interface Gun :NSObject
{
@public
NSString *_size;
int _countnum;
}
-(void)shoot;
@end
@implementation Gun
-(void)shoot
{
if(_countnum==0)
{
NSLog(@"没有子弹了,你打个毛线");
}
else
{
_countnum-=1;
NSLog(@"子弹剩余的个数是%d",_countnum);
}
}
@end
@interface Person : NSObject
{
@public
NSString *_name;
}
-(void)kaiqiang:(Gun *)gun;
@end
@implementation Person
-(void)kaiqiang:(Gun *)gun
{
[gun shoot];
}
@end
int main()
{
Gun *ak=[Gun new];
ak->_size=@"ak47";
ak->_countnum=3;
Person *per=[Person new];
[per kaiqiang:ak];
[per kaiqiang:ak];
[per kaiqiang:ak];
[per kaiqiang:ak];
[per kaiqiang:ak];
}
|
|