C + + encourages the use of multiple files when developing programs, an effective organizational strategy is to use header files to define user types, provide function prototypes for functions that manipulate user types, and to place function definitions in a separate source code file. The header file and the source code file define and implement user-defined types and how they are used. Finally, Mian () and other good books that use these functions are placed in the third file.
C + + Storage scenarios determine how long the variable remains in memory (storage continuity) and which part of the program can access him. An automatic variable is a variable defined in a code block that only exists when the program executes to the code block that contains the definition, and is visible. An automatic variable can be declared by using the storage type specifier, auto and register, or not using a specifier at all, as with auto. The register specifier prompts the compiler that the variable is used very frequently.
Static variables exist throughout the execution of the program, and for variables defined outside the function, all functions that are in the file that are behind the definition of the variable can use it (file scope) and can be used in other files of the program (external link). For another file to use this variable, you must declare it using the extern keyword. For variables that are shared among files, you should include in a file a definition declaration (no extern) and include a reference declaration in other files (using extern). Variables defined by using the keyword static outside of a function are scoped to the entire file, but not to other files (internal link sex). Variables defined with the keyword static in a code block are limited to that code fast (local scope, no link), but all the time throughout the execution of the program, it persists and retains its original value.
By default, C + + functions are externally linked, so they can be shared among files, but the link to a function that uses a keyword static qualification is internal and is limited to the file in which it is defined.
namespace allows you to define a named range in which identifiers can be declared. This is done to reduce the name conflict, especially when the program is very large and uses the code of multiple vendors. You can make a marker in a namespace available by using the scope resolution operator, using declarations, or using compilation directives.