[C + +] The difference between "arrow" and "dot (.)"

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/gyymen/article/details/4962873

First introduce the structure in C + +. For a structure:

struct mystruct{    int member_a;};

If you have a variable mystruct s, you can use the member elements in the following:

S.member_a = 1;  

If you use pointer method access, such as MyStruct * PS, then the same access must use the following form:

(*ps). member_a = 1;  

Or

When defining a class object as a pointer object, C + + uses a pointer to a member of the class, which needs to be used when defining a generic object. Points to a member in a class.
For example:

Class A{public    Play ();}

If defined as follows:
A *p is used: P->play (); The left is the structure pointer.
A p is used: P.paly (); On the left is the structure variable.


Summarize:
Arrow (): The left must be a pointer;
Point number (.): The left must be an entity.

[C + +] The difference between "arrow" and "dot (.)"

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.