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