auto、extern、register、static

 1, auto keyword

The default is omitted, the allocation of space within the stack, into local and global variables

 

2, extern keyword, across files

Declare a global variable or function, the variable is defined in other files as a global variable (Auto), to use a variable type is static, the error 'undefined variables'

 3, register keyword

Register variable definitions, C & fetch address operator can not effect such variables, C ++, but may have limitations, benefits: improve the reading speed    link

 

4, static keyword, Scope: The file is declared

 Local static variable, compilation phase in a static area allocated space, during the entire life cycle of program execution

Object-oriented in use:

    Modified member variable outside the class by class name or object name is initialized (type base :: var = key;), shared by all objects (including the derived class object), also independently access

    Modifying member function, shared by all objects, without this indicator, can only access static class members ; can independently access (accessible base :: fun (when not create the object);)

Hidden Role: in a project, not add static members are prefixed with global visibility, other source files can be accessed. The use of static file scope can define the characteristics of the members of the same name in different files without worrying about naming conflicts.

Note: You can not use const and static member functions simultaneously modified

 

 

Guess you like

Origin www.cnblogs.com/guoyujiang/p/11889732.html