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.

相关文章:

  • 2022-01-25
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
猜你喜欢
  • 2022-02-15
  • 2021-11-21
  • 2021-05-25
  • 2021-10-02
  • 2021-12-03
  • 2022-01-31
  • 2021-09-03
相关资源
相似解决方案