首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

Objective-C里多个参数步骤的语法

2013-02-03 
Objective-C里多个参数方法的语法声明时是这样@interface C : NSObject+(int) fun: (int) a second: (int)

Objective-C里多个参数方法的语法
声明时是这样


@interface C : NSObject
+(int) fun: (int) a second: (int) b;
@end

定义是这样:

@implementation C
+(int) fun: (int) a second: (int) b
{
    return a * b;
}
@end

使用时是这样:

int a = [C fun: 2 second: 3];

fun应该是理解为函数名吧?那second理解为什么?
如果second理解为第二个参数的名字,那b又是什么?同时fun又是什么?
object-c 语法
[解决办法]
这个方法叫fun:second: 注意两个冒号
second是方法名的一部分
[解决办法]
可以当作是第二个参数的占位符。就是这个格式而已。用用就习惯了。
[解决办法]
+(int) fun: (int) a second: (int) b;
照书上写的转成C后变成:
int funsecond(int a,int b);

+:实例函数
-:成员函数

这跟C来说比较特例一点?有点C++的味道?
我也还在看书中?

热点排行