Basic concepts of C ++ static member functions

Source: Internet
Author: User

1. The address of the C ++ static member function can be stored as a normal function pointer, while the address of a common member function must be stored as a class member function pointer.
Example:

1. class base {
2. Static int func1 ();
3. Int func2 ();
4 .};
5. INT (* pf1) () = & base: func1; // common function pointer
6. INT (base: * pf2) () = & base: func2; // member function pointer

2. static member functions cannot call non-static members of a class. Because the C ++ static member function does not include the this pointer.


3. c ++ static member functions cannot be declared as virtual, const, and volatile functions at the same time.

Example:

1. class base {
2. Virtual static void func1 (); // Error
3. Static void func2 () const; // Error
4. Static void func3 () volatile; // Error
5 .};

The last point is that static members can be accessed independently, that is, they can be accessed without creating any object instance.

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.