Member properties in C + + classes for this class, whether member properties can be understood as global variables in this class __c++

Source: Internet
Author: User

Ext: https://zhidao.baidu.com/question/519474836.html

Class Clock

Public
.........
Private
int hour;
int minute;
int second;
};
Member variables, Hour,minute,second for the clock class, whether the above variables can be understood as global variables.

Answer: You can not understand this, yo, global variables are public, who can be modified, and instantiated, the member variables of the class can only be owned by the instantiated object. For example, your family is a class, and everyone in your home can be understood as an instantiated object of a class, for example, your hand is a member variable, and this is a member variable that only you can control and other instantiated objects cannot use.

Note: It is not good to understand the overall situation, because the member variable is a part of the instantiated object, the equivalent of the object's component, the object does not die, the variable will not die.

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.