OC 对象作为方法的参数连续传递
发布日期:2021-06-30 22:37:04 浏览次数:2 分类:技术文章

本文共 853 字,大约阅读时间需要 2 分钟。

这里写图片描述

实现1:

#import 
@interface Gun:NSObject{
@public NSString *_type; int _bllutCount;}-(void)shot;@end@implementation Gun-(void)shot{ if(_bllutCount >0){ _bllutCount--; } NSLog(@"%@ is shoting ..., the bllut is leave :%d",_type,_bllutCount);}@end@interface Person : NSObject{
@public NSString *_name; int _life; int _level;}-(void)fire:(Gun *) gun;@end@implementation Person-(void)fire:(Gun *) gun{ [gun shot];}@endint main(int argc, const char * argv[]){ @autoreleasepool { // Person *p = [Person new]; p->_name = @"tom"; p->_life = 100; p->_level = 10; Gun *gun = [Gun new]; gun ->_type = @"china"; gun ->_bllutCount = 6; [p fire:gun]; [p fire:gun]; [p fire:gun]; NSLog(@"Hello, World!"); } return 0;}

实现2:

转载地址:https://lovoo.blog.csdn.net/article/details/51457198 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android md5加密工具类
下一篇:Android 使用三级缓存实现对图片的加载

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月24日 17时30分24秒