繁体   English   中英

为什么此方法声明中没有*?

[英]Why is there no * in this method declaration?

这是Apple文档中的方法声明: 学习Objective-C:入门

- (void)insertObject:(id) anObject atIndex:(NSUInteger) index

为什么NSUInteger之后没有* 我以为所有对象都是指针类型,所有强类型指针都必须在其后带有*字符。

NSUInteger不是对象类型,它是unsigned inttypedef

在这种情况下,您真正​​想要使用*的唯一原因是,您想获取一个int的地址并将其存储在其中。 (某些库通过错误消息传递来实现)。 一个例子:

-(void) methodName: (NSUInteger *) anInt {
    *anInt = 5;
}

NSUInteger a;
[obj methodName: &a]; //a is now 5

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM