C ++ static member

Source: Internet
Author: User

1. static member variables in C ++ are part of the class, but they are not part of each object of the class.

A static member has only one unique copy, but each object does not have a copy as a regular non-static member.

Similarly, a function that needs to be called for a specific object but does not need to be a static member function.

2. Static members can also be referenced like any other member. In addition, reference to static members does not need to mention any objects. On the contrary, you should add a class name as a qualified word to the member name.

(P203, C ++ProgramDesign Language, section 10.2.4)

Question 1: a static member has only one copy.

A class generates three instances, but the static members in this class have only one copy in the memory, and they are in the static storage area and are no longer heap or stack. But what if the derived class of this class is used? Are you using the same static member?

Question 2:

What is the difference between global variables and global variables? Is there a limited scope?

 

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.