1. The address of a static member function can be stored with a normal function pointer, whereas an ordinary member function address needs to be stored with a class member function pointer.
1 class Base{ 2 Public: 3 Static intfunc1 () {};4 intFunc2 () {};5 }; 6 7 8 intMain ()9 {Ten int(*PF1) () =&Base:: func1;//normal function pointers One int(Base::* PF2) () =&Base:: FUNC2;//member function pointer A return 0; -}
2. Static member functions can not invoke non-static members of a class. Because the static member function does not contain the this pointer.
3. Static member functions cannot be declared at the same time as virtual, const, and volatile functions.
4. Static member functions can be accessed without creating any instance objects.
1#include <iostream>2 using namespacestd;3 4 classM5 { 6 Public: 7Minta) { 8A=A;9b+=A;}Ten Static voidF1 (m); One Private: A intA; - Static intB; - }; the - voidm::f1 (m) - { -cout <<"a="<< M.A <<Endl; +cout <<"b="<< B <<Endl; - } + A intm::b=0; at - intMain () - { -M P (5), Q (Ten); -m::f1 (P); -m::f1 (Q); in return 0; -}
[[email protected] test]$./a. out a=5b=a=tenb =
C + +: static member functions