Reprinted ---- c ++ static function modified role and significance

modified static function called static functions, there are two static function, classified according to the place in which they appear: 

 If the static function appears in the class, then it is a static member function; 

 the role of a static member function is: do not call this function You can access or modify any object (non-static) data members. 

 In fact well understood, static members (variables and methods) belongs to the class of the class itself, will allocate memory when the class is loaded, you can go directly accessed by class name; non-static member (variables and methods) belonging to the object class, so will allocate memory only objects in the class of produce (create an instance of the class), then (instances) to access by object class. 
 If it is not present in class, then it is a normal global static functions. 

 Such a function of the difference between static and normal function is: with a modified static function defined in this source file, can not be called the source code files other than the present document. The normal function, the default is extern, which means it can be called by other code files. 

 With the keyword static, the function was defined as a static function before the return type of the function. Ordinary function definitions and declarations of extern by default, but only in static function declarations visible among his papers, other documents can not be used. Therefore, the definition of static function has the following advantages: 
 <1> other files can define functions with the same name without conflict. 
 <2> static function can not be used by other files. 

Reprinted: https: //www.cnblogs.com/happyamyhope/p/10429434.html

Guess you like

Origin www.cnblogs.com/hellowooorld/p/11281654.html