Geekband-secondweek-c++ 's static

Source: Internet
Author: User
Some of the data compiled from think in C + + 1, static meaning one: static storage, that is, static data area allocation of memory, it is more than the local variable life cycle longer; meaning two: The Connection property is a local property, that is, it is connected by default, control the visibility of the name, only within the defined block is visible; Default inline: The properties of the interconnect are very good, well suited to the requirements of encapsulation control visibility, such as static, const, inline functions, which are internally linked by default, especially const,c default external connection, C + + default internal connection, there are some differences On the Connection property: extern and static are reciprocal, and the function and the global variable default extern are out-of-bounds, unless explicitly declared as the benefit of statically member variables in the 2, C + + static members: stored like a global variable, the name is hidden within a limited range, It also provides a means of communication for multiple objects of a class, the memory of a static member variable is allocated to the global zone, and differs from the normal member variable, when the size of the class is computed with sizeof (), the static member variable is not in the inside, the static member variable does not belong to a class object, but the entire class, for all objects , static member variables must be initialized outside of the class, access to static members of a class can be accessed through a scope operator, a class object, a reference, a pointer to a class object, and when the member variable of a class is a const static type, it can be defined in the class body or outside the class body;

Because a static member is not part of any object, a static member function cannot be const,const by the gods and promises not to modify the object to which the function belongs. Static member functions cannot be declared as virtual functions;

Requirements: declaration within a class, must be defined outside the class, not allowed inline definition;

Geekband-secondweek-c++ 's static

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.