这是什么' - >'在C / Objective-C的意思吗? [英] What does this ' ->' mean in c/objective-c?

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

问题描述

我找了一些code和我遇到一些语法,我不知道的意思来了。什么是' - >'?意味着

   - (无效)getTransformValues​​:(结构transformValues​​_ *)电视
{
    电视> POS = positionInPixels_;
    电视> scale.x = scaleX_;
    电视> scale.y = scaleY_;
    电视>旋转= rotation_;
    电视> skew.x = skewX_;
    电视> skew.y = skewY_;
    电视> AP = anchorPointInPixels_;
    电视>可见= visible_;
}


解决方案

箭头操作符( - >)中您可以使用点运算符('。')相同的地方被使用,但有一个指针结构,而不是该结构的目的

  typedef结构_Person {
    字符名称[200];
    unsigned int类型的年龄;
}人;

如果你创建了一个结构的目的,你可以使用点运算符,以便访问其成员:

  INT的main()
{
    人P1;    的strcpy(p1.name巴尔塔萨);
    p1.age = 36;
}

然而,如果你指向一个结构,而不是结构本身,你只能使用箭头运营商,还是有点更复杂点操作:

  INT的main()
{
    人P1;
    人* ptrPerson =放大器; P1; // ptrPerson指向P1    的strcpy(ptrPerson->的名字,巴尔塔萨);
    ptrPerson->年龄= 36;
}

正如我前面所说,你仍然可以使用点运算符:

  INT的main()
    {
        人P1;
        人* ptrPerson =放大器; P1; // ptrPerson指向P1        的strcpy((* ptrPerson).name和巴尔塔萨);
        (* ptrPerson)。年龄= 36;
    }

当然,这一切的讨论涉及到很多话题,如指针,堆等希望这会有所帮助。

I'm looking over some code and I came across some syntax that I don't know the meaning of. What does the '->' mean?

-(void) getTransformValues:(struct transformValues_*) tv
{
    tv->pos         = positionInPixels_;
    tv->scale.x     = scaleX_;
    tv->scale.y     = scaleY_;
    tv->rotation    = rotation_;
    tv->skew.x      = skewX_;
    tv->skew.y      = skewY_;
    tv->ap          = anchorPointInPixels_;
    tv->visible     = visible_;
}

解决方案

The arrow operator ('->') is used in the same place you would use the dot operator ('.'), but with a pointer to a structure instead of an object of that structure.

typedef struct _Person {
    char name[200];
    unsigned int age;
} Person;

If you created an object of that structure, you would use the dot operator in order to access its members:

int main()
{
    Person p1;

    strcpy( p1.name, "Baltasar" );
    p1.age = 36;
}

However, if you a pointer to a structure, instead of the structure itself, you could only use the arrow operator, or a little bit more complex dot operator:

int main()
{
    Person p1;
    Person *ptrPerson = &p1;    // ptrPerson points to p1

    strcpy( ptrPerson->name, "Baltasar" );
    ptrPerson->age = 36;
}

As I said above, you could still use the dot operator:

 int main()
    {
        Person p1;
        Person *ptrPerson = &p1;    // ptrPerson points to p1

        strcpy( (*ptrPerson).name, "Baltasar" );
        (*ptrPerson).age = 36;
    }

Of course, all of this discussion involves a lot more topics, such as pointers, the heap, etc. Hope this helps.

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

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