C++: -> Operator
The arrow operator, -> (that's a minus sign followed immediately by a greater than),
dereferences a pointer to select a field.
It is common to dynamically allocate structs, so this operator is
commonly used.
For example,
struct Point {
int x;
int y;
};
Point* p; // declare pointer to a Point struct
p = new Point; // dynamically allocate a Point
p->x = 12; // set the field values.
p->y = 34;
The -> operator is convenient, but not necessary
There usual pointer dereference operator (*) and field selection operator (.)
can be used to reference fields. The last two lines of the above example
could be written as
(*p).x = 12; // set the field values.
(*p).y = 34;
Note that the parentheses are needed to control the order of operator evaluation.
Arrow is more commonly used than the *. combination because it's more readable.