The declared functions in the class have three meanings compared to the class:
1. This pointer is available
2. The function is in the Action Area of the class.
3. Private part of the category
4. can be inherited
Non-static member functions have 1234
Static member functions have 234
Youyuan function has 3
The difference between a static member function and a friend function is only the difference in the role region.
When a friend function is used globally, the same name conflict may occur.
Although the namespace can solve some problems, I prefer to use static member functions =
1. The address of the static member function can be stored by the common function pointer, while the common member function address needs to be stored by the class member function pointer. Example:
Class base {
Static int func1 ();
Int func2 ();
};
INT (* pf1) () = & base: func1; // common function pointer
INT (base: * pf2) () = & base: func2; // member function pointer
2. static member functions cannot call non-static members of a class. Because the static member function does not include the this pointer.
3. static member functions cannot be declared as virtual, const, and volatile functions at the same time. Example:
Class base {
Virtual static void func1 (); // Error
Static void func2 () const; // Error
Static void func3 () volatile; // Error
};
The last point is that static members can be accessed independently, that is, they can be accessed without creating any object instance.