C + + basic syntax

Source: Internet
Author: User

First, static member variables and static member functions

1. Common member variables each object has its own copy, and the static member variable is one copy, shared for all objects

2. Ordinary member functions must be specific to an object, whereas static member functions do not specifically work on an object.

3. Therefore, static members do not need to be accessible through objects

4. Static member variables are essentially global variables, and even if an object does not exist, the static member variable of the class exists. A static member function is essentially a global function.

5. Set static members The purpose of this mechanism is to write global variables and functions that are closely related to certain classes into the class, looking like a whole, easy to maintain and understand.

Attention:

1. A static member variable must be described or initialized in the file that defines the class, or the compilation will pass, but the link will not pass.

2. In a static member function, you cannot access a non-static member variable or call a non-static member function.

C + + basic syntax

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.