In C ++, the arrow operator (->) vs the vertex operator (.)

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.