In C ++, the arrow operator (->) vs the vertex operator (.)
A pointer is displayed on the left.
An object is on the left.
If P is a pointer, p-> function ();
If P is an object, P. function ();
Remember-> the left must be a pointer, and the left must be an object or a struct, generally a class object.
First, we will introduce the structure in C ++. For a structure,
Struct mystruct
{
Int member_a;
};
If there is a variable mystruct S, you can use
S. member_a = 1;
If you use the pointer Method for access, such as mystruct * ps, the same access must be in the following format:
(* PS). member_a = 1;
Or
PS-> member_a = 1;
In C ++, when defining a class object as a pointer object, you need to use-> point to a member in the class. when defining a general object, you need to use ". "pointing to a member in the class .......
For example:
Class
{
Public
Play ();
}
If the definition is as follows:
A * P: p-> play (); Structure pointer on the left.
For a p, use P. paly (); for the left, use the structure variable.
Summary:
Arrow (->): the pointer must be left;
Point (.): The object must be on the left.