1. Compiling separately
What is often included in the 1.1 header files:
- Function prototypes
- Symbolic constants defined with # define or const
- Structure Declaration
- class declaration
- Template declaration
- Inline declaration
1.2 You only need to add the source code files to the project without having to add the header files. This is because using the # include management header file.
1.3 Avoid including the same header file multiple times
1 #ifndef Coordin_h_ 2 #define Coordin_h_3// place include file contentshere4#endif
2. Storage continuity, scope, and connectivity
1. Storage solution:
- Automatic storage persistence-variables declared in the function definition, 2 types
- Static storage persistence-variables defined outside the function and variables defined using the keyword static, 3 kinds
- Thread storage Persistence (C++11)-Thread_local declaration
- Dynamic storage persistence-memory allocated with the new operator persists until it is disposed with the delete operator or the program ends
2. The names that are linked externally can be shared between files, and the internal name of the link is shared only by functions in one file.
3. Using the keyword register, it is recommended that the compiler use CPU registers to store automatic variables, which are designed to increase the speed of accessing variables. (Same as the previous usage of auto, c++11 obsolete).
4. Static storage persistence variables provide 3 features: external linkage (external declaration of code blocks), internal chaining (code block external static declaration), and no connectivity (code block internal static declaration). By default, static variables that are not explicitly initialized are set to 0 by the compiler.
5. c++11 New keyword constexpr to increase the way you create constant expressions.
6. The reference declaration uses the keyword extern and is not initialized. If you want to use an external variable in more than one file, you only need to include the definition of the variable in a file (a single definition rule), but in all other files that use the variable, you must declare it with the keyword extern.
7. The scope resolution operator (::) indicates that the global version of the variable is used.
C + + Primer Plus 6th reading notes-Nineth chapter memory models and namespaces