Memory Model and namespace of C ++ Primer, primer Model
C ++ Primer Memory Model and namespace 1. header file
Header files include: function prototype; Use # define or const-defined symbolic constants; Structure Declaration; Class Declaration; template declaration; Inline Function
// Avoid multiple inclusion of the consent header file # ifndef COORDIN_H_EXAM # define COORDIN_H_EXAM... # endif
2. Storage continuity, scope, and connection
Link: how the name is shared among different units.
Automatic Storage Persistence: variables defined in the function (including parameters); Scope: local code blocks; connectionless (stack) static storage persistence: variable defined outside the function and variable defined by the static keyword thread storage continuity (C ++ 11): keyword thread local Declaration (same length of life cycle and thread) Dynamic Storage continuity: keyword new declaration (HEAP)
Three Links for static storage persistence variables:
External link (accessible in other files): external Declaration of the code block (no static) Internal Link (accessible only in the current file ): the code block is declared connectionless with static outside (only accessible in the current code block): the code block is declared with static.
3. namespace
Namespace exam {// declare variables, function prototype, structure class declaration} // cannot be located in the code block using namespace exam; using exam ::...; // nested namespace t1 {using t2 ;...}