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