什么是“-"在目标 C 中? [英] What is "->" in Objective C?

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

问题描述

我在在 Mac 上学习 Objective C"的示例代码中多次看到这个运算符出现.

I've seen this operator pop up quite a few times in example code in "Learn Objective C on the Mac."

我相信它是Objective C继承的C语言中的一个操作符.我尝试使用谷歌搜索并搜索 Stack Overflow,但奇怪的是什么也没找到.

I believe it's an operator in the C language which Objective C inherits. I tried Googling and searching Stack Overflow and oddly nothing came up.

有英文名字吗?

推荐答案

它与结构有关.

当我们在堆栈上有一个本地可用的结构时,我们使用 . 操作符访问它的成员.例如:

When we have a struct available locally on the stack, we access its members with the . operator. For example:

CGPoint p = CGPointMake(42,42);
NSLog(@"%f", p.x);

然而,如果我们有一个指针指向一个结构,我们必须使用->操作符:

However, if we instead have a pointer to a structure, we have to use the -> operator:

CGPoint *p = malloc(1*sizeof(CGPoint));
p->x = 42.0f;
NSLog(@"%f", p->x);
free(p);

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

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