C + + Object-oriented learning-static members of a class

Source: Internet
Author: User

1 static data members2 1,sizeofThe operator does not evaluate static members. 3 4 2, the order in which static member data is initialized is the order in which they are declared outside the class body. 5 6 3, a static data member is shared by all objects of the class, including the derived class object of the class. 7 8 4, static member data can also be classified as public, private, and protected static members. 9 for public static members, which can be accessed through the object of the class, or directly through the class name. Ten private and protected static member data can only be accessed by the public member function of the class.  One  A 5, the static member data for the class already exists and can be referenced before any objects are created.  -  - 6, the type of a static data member can be the type of the owning class, and non-static data members are not allowed.  the classstudent{ -      Public: -         StaticStudent stu1;//static data member, belonging to the entire class, memory only one copy -Student STU2;//Error +Student *pstu;//Pointers -Student &rstu;//References + }; A STUDENT::STU1::STU1::STU1::...::STU1 is equivalent to STUDENT::STU1.  at initialization of a static data member when it is a custom data type - classa{ -      Public: -Aint); - }; - classb{ in     Private: -         StaticA; to }; +A B::a (2); -  the  * Static member functions $ 1, static data members and static member functions belong to the entire class, not to a specific object. Allocates storage space for static member data when the program starts running. Panax Notoginseng Therefore, a reference to a static member function does not require an object name (reference to the class name).  - classstudent{ the      Public: +         Staticfunc (); A }; the  + intMain () { -Student::func ();//here! $     return 0; $}

C + + Object-oriented learning-static members of a class

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.