objective-c 基础语法和习题 / 类 详解/ 函数多参数的几种用法
2014-03-12 11:49
861 查看
函数多参数的几种用法
使用 参数名,例如:'over',这里 'over'可以换成其他的单词。
使用 参数名,例如:'over',这里 'over'可以换成其他的单词。
1.#import <Foundation/Foundation.h> 2. 3.@interface Animal: NSObject 4. 5.@property int Speed, Legs; 6. 7.-(void) display; 8. 9.-(void) set_speed:(int) speed over:(int) legs ; 10. 11.@end 12. 13.@implementation Animal 14. 15.@synthesize Speed,Legs; 16. 17.-(void) display 18.{ 19. NSLog(@"run speed %i",Speed); 20. NSLog(@"I have %i legs",Legs); 21.} 22. 23.-(void) set_speed:(int) speed over: (int) legs 24.{ 25. Speed = speed; 26. Legs = legs; 27.} 28.@end 29. 30. 31.int main(int argc, const char * argv[]) 32.{ 33. 34. @autoreleasepool { 35. Animal *dog; 36. 37. dog = [Animal alloc]; 38. dog = [dog init]; 39. 40. 41. [dog set_speed:30 over: 4]; 42. [dog display]; 43. // insert code here... 44. NSLog(@"Hello, World!"); 45. 46. } 47. return 0; 48.}不使用 参数名:
1.#import <Foundation/Foundation.h> 2. 3.@interface Animal: NSObject 4. 5.@property int Speed, Legs; 6. 7.-(void) display; 8. 9.-(void) set_speed:(int) speed :(int) legs ; 10. 11.@end 12. 13.@implementation Animal 14. 15.@synthesize Speed,Legs; 16. 17.-(void) display 18.{ 19. NSLog(@"run speed %i",Speed); 20. NSLog(@"I have %i legs",Legs); 21.} 22. 23.-(void) set_speed:(int) speed : (int) legs 24.{ 25. Speed = speed; 26. Legs = legs; 27.} 28.@end 29. 30. 31.int main(int argc, const char * argv[]) 32.{ 33. 34. @autoreleasepool { 35. Animal *dog; 36. 37. dog = [Animal alloc]; 38. dog = [dog init]; 39. 40. 41. [dog set_speed:30 : 4]; 42. [dog display]; 43. // insert code here... 44. NSLog(@"Hello, World!"); 45. 46. } 47. return 0; 48.}
相关文章推荐
- objective-c 基础语法和习题 / 类 详解
- objective-c 基础语法和习题 / 类 详解/合成存取
- objective-c 基础语法和习题 /类 详解/ . 属性的方法
- ios-基础用法之【2】-Objective-c 语法,类/属性/函数
- objective-c 基础语法和习题 / self 的用法
- Python基础之函数用法实例详解
- 详解Objective-C可变参数函数定义
- Python学习之基础语言篇——函数参数详解
- php引用(&)变量引用,函数引用,对象引用和参数引用用法详解
- 详解Objective-C可变参数函数定义
- Objective-C 基础语法详解
- php引用(&)变量引用,函数引用,对象引用和参数引用用法详解
- C++学习笔记:函数指针语法基础以及函数指针做函数参数的思想剖析
- Swift基础语法: 23 - Swift的闭包简介, Sorted函数, 闭包的表达式语法, 根据上下文推断类型, 参数名简写, 运算符函数
- WordPress分类列表函数:wp_list_categories用法及参数详解举例
- Python基础之函数用法实例详解
- Swift如何调用Objective-C的可变参数函数详解
- C#基础语法:方法参数详解
- 【IOS】objective-c 基础语法和习题一
- Lua函数的几种用法详解