static (static) variable of C + + Foundation

Source: Internet
Author: User
static indicates function :1, in the function body, the value of the static variable remains constant (memory function) 2, is a local global function, that can only be accessed by the function of this module (hidden function) static variable: The difference between a static global variable and a normal global variable: the static variable is initialized only once (that is, it cannot be defined repeatedly), which prevents the difference between a static local variable and a normal local variable being referenced in another file cell: The static variable value is initially The next operation is based on the last value (the second time the initialization statement is skipped directly) the static function:The static function can only be valid in one source file, static in other invalid class ofsource file: 1, regardless of the number of class objects are defined, Static data members are always only one copy, used as a share 2, static data members are stored in the global data area, when defined to allocate space, even if the class is not instantiated, static data members can be used 3, public, private, protect access 4, Static member functions are initialized outside the class (the class simply declares that it is initialized in the CPP), but at this point do not add the static keyword 5, static data members do not have the this pointer (ordinary class member functions have), so you cannot access non-static member functions in the class, only member functions can be accessed Advantages:1, there is no global name Conflict 2, the information can be hidden, can be private note: Do not define a static variable in the header file, do not define any variables in the header file

static (static) variable of C + + Foundation

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.