c++ arrow operator ,, –> Operator,,,指针专属

C++ has an operator that can be used with a pointer to simplify the notation for
specifying the members of a struct or a class. The arrow operator , -> , combines
the actions of a dereferencing operator, * , and a dot operator to specify a member of
a dynamic struct or class object that is pointed to by a given pointer. For example,
suppose you have the following definition:
struct Record
{
int number;
char grade;
};
The following creates a dynamically allocated variable of type Record and sets the
member variables of the dynamic struct variable to 2001 and 'A' .
Record *p;
p = new Record;
p->number = 2001;
p->grade = 'A';
The notations
p->grade
and
(*p).grade
have the same meaning. However, the first is more convenient and is almost always the
notation used.

原文链接: https://www.cnblogs.com/gisbeginner/archive/2012/10/30/2746328.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++ arrow operator ,, –> Operator,,,指针专属

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/67535

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午12:51
下一篇 2023年2月9日 下午12:52

相关推荐