是什么->意思是? [英] What does -> mean?

查看:167
本文介绍了是什么->意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Objective-C的相对新手(仅研究过Arron Hillegras的书),并且对我在Apple的一个代码示例中发现的以下代码片段感到困惑,特别是->是什么意思?

I'm a relative newbie to Objective-C (only studied Arron Hillegras's book) and am confused by the following snippit of code I've found in one of Apple's code examples, in particular what does the -> mean?

-(id) initWithNumbers:(NSArray *)numbers
{
    self = [super init];
    if (self != nil)
    { 
       self->_numbers = [numbers copy];
    }
    return self;
}

在头文件_numbers中声明为

In the header file _numbers is declared as

NSNumber * _number;

(下划线对于我记得在某处所读的内容具有一定的意义,但此刻也使我难以理解.

( the underscore has some significance from what I recall reading somewhere but that too eludes me at the moment.

谢谢 罗宾

推荐答案

->是普通的C运算符,用于将 pointer 的成员访问到结构; .运算符用于访问结构的成员.因此:

-> is a normal C operator for accessing the members of a pointer to a struct; the . operator is for accessing members of a struct. Thus:

a->b

被翻译为

(*a).b

由于Objective-C对象是指向其全部结构的指针,因此可用于访问实例变量.

Since Objective-C objects are pointers to structs underneath it all, this works for accessing instance variables.

这篇关于是什么->意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆