source file notice

来源:互联网 发布:被明星搭讪 知乎 编辑:程序博客网 时间:2024/05/21 09:50

The result of preprocessing is called a translation unit. This unit is what the compiler proper works on and what the
C++ language rules describe.

 

Names of functions, classes, templates, variables, namespaces, enumerations, and enumerators must be used consistently across all translation units unless they are explicitly specified to be local.


A name that can be referred to only in the translation unit in which it is defined is said to have internal linkage.

 

An inline function  must be defined – by identical definitions – in every translation unit in which it is used.

 

By default,const and typedef have internal linkage.

 

Global variables that are local to a single compilation unit are a common source of confusion and are best avoided. To ensure consistency, you should usually place global const and inline in header files only.

 

An unnamed namespace  can be used to make names local to a compilation unit. The effect of an unnamed namespace is very similar to that of internal linkage.

 

In C and older C++ programs, the keyword static is (confusingly) used to mean ‘‘use internal linkage’’ . Don’t use static except inside functions  and classes.