/* Function, C ++ static date, March 13, 2013 environment, ubuntu1204-gcc blog, login <iostream> Using STD: cout; Using STD: Endl; # define P1 cout <Endl; # define P2 (x) cout <X; # define P3 (x) cout <x <Endl; // The scope of the static variable in the function body is the function body, unlike the auto variable, the memory of this variable is only allocated once, so its value remains the last value during the next call; void F () {// static variables are allocated in the static zone, so the default value is 0. The default value of common variables is the random number static int fs1; P3 (fs1 ++)} // static variables in the file Global variables can be accessed by all functions in this file, but cannot be accessed by other functions outside the module. Static int GS1 = 110; // The static function in the file can only be called by other functions in the file, and the scope of use of this function is limited // static void F1 () in the file where it is declared () {P3 (-- GS1)} Class A {public: // use static member variables as the default parameter A (INT I = m_si): m_ I (I) {} // The static member function belongs to the entire class and does not have this. Therefore, it can only be declared as a class's static variable as a // member variable and cannot be declared as a const function, cannot be declared as a virtual function. Static void F () {P3 (m_si ++) // error: the use of the member 'a: m_ I 'in the static member function is invalid // P3 (m_ I)} public: // static member variables in the class belong to the entire class, and only one copy of all objects in the class; // static members are restricted within the class scope, therefore, you can avoid global conflicts or other class conflicts, and // you can control its access permissions. Very convenient. Static int m_si; // error: iso c ++ does not allow the initialization of a very large number of static members in the Class 'M _ si1' // static int m_si1 = 120; // but static const Initialization is allowed. This is a constant. Static const int m_i2 = 120; int array [m_i2]; static const double m_sd = 0.1; private: int m_ I ;}; // static member variables must be defined outside the class. Otherwise, the message "undefined reference to 'a: m_si' int A: m_si = 11" is displayed. // if the base class defines static members, there is only one such member in the inheritance hierarchy. No matter how many derived classes are derived from the base class //, each static member has only one instance. Class A1: Public A {public: // if you use a base class, the base class value such as F () is used. You must use the derived class's own value such as F1 () static void F1 () {P3 (m_si ++)} public: // redefines static int m_si;}; int A1: m_si = 33; int main () {f (); F (); p1p3 (GS1) p1f1 (); p1a A;. F (); p1a1 A1; a1.f (); A1 A11; a11.f (); A1 A12; a12.f1 (); A1 A13; a13.f1 (); P1}/* $. /static.exe 0121101091112133334 */