C + +-static member functions

Source: Internet
Author: User

Static member functions in C + + are part of the entire class, not an object, so you do not need to create objects to access

1. Function definitions that appear outside the class body cannot specify the keyword static;
2. Static members can access each other, including static member functions to access static data members and access static member functions;
3. Static member functions and static data members can be accessed arbitrarily by non-static member functions;
4. Static member functions cannot access non-static member functions and non-static data members;
5. Because there is no additional overhead for this pointer, the static member function has a slight increase in speed compared to the global function of the class;
6. Call the static member function, which can be accessed with the member access operator (.) and (a) call a static member function for an object of a class or a pointer to a class object.
When all objects of the same class use a quantity, for this common amount, a static data member variable can be used, which takes the same value for all objects of the same class. Static member variables can only be called by static member functions. Static member functions are also shared by all objects in the same class. Only static member variables and static member functions can be called.

C + +-static member functions

Related Article

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.