Internal connection: If a name is local to his compilation unit and does not conflict with the same name in other compilation units at the time of the connection, then the name has an internal connection (note: Sometimes the declaration is considered to be non-connected, and here we unify as an internal connection).
The following conditions have an internal connection:
A) any statement
b) The definition of static free functions, static friend functions, static variables in namespaces (including global namespaces)
c) Enum definition
d) Definition of the inline function (including free and non-free functions)
e) Definition of class
f) Const constant definition in namespaces
g) Definition of Union
External connection: In a multi-document program, if a name can interact with other compilation units at the time of connection, then the name has an external connection.
External connections are available for the following situations:
A) class non-inline functions always have an external connection. Include class member functions and class static member functions
B) class static member variables always have an external connection.
c) namespaces (including global namespaces) non-static free functions, static friend functions, and non-static variables
The following examples illustrate:
A) Declaration, enum definition, union definition with internal connection
Any declaration, enum definition, and union definition will not generate a join symbol after compilation, that is, declarations with the same name in different compilation units and enums, union definitions do not cause errors to discover multiple symbols at the time of the connection.
typedef int INT; typedef declaration, internal Connection
Enum color{red}; Enum definition, internal connection
Union X//union Definition, internal connection
{
Long A;
Char b[10];
};
int main (void)
{
Int i = red;
return i;
}
typedef int INT; Re-declares an int type alias in a.cpp, no error occurs when connecting
Enum Color{blue}; An enum Color was redefined in a.cpp, and no error occurred while connecting
Const INT I =blue; const constant definition, internal connection
Union X//union Definition, internal connection
{
Long A;
Char b[10];
};
b) Static free functions, static friend functions, static variables, const constants in namespaces define internal connections
Namespace test
{
int foo (); function declaration, internal connection
static int i = 0; namespace static variable definition, internal connection
static int foo () {return 0;}//namespace static function definition, internal connection
}
static int i = 0; Global static variable definition, internal connection
static int foo () {return 1;}//global static function definition, internal connection
const int k = 0; Global const constant definition, internal connection
int main (void)
{
return 0;
}
Namespace test
{
int i = 0; namespace variable definition, external connection
int foo () {return 0;}//namespace function definition, external connection
}
int i = 0; global variable definition, external connection
int k = 0; global variable definition, external connection
int foo () {return 2;}//global function definition, external connection
In the global namespace, main.cpp defines the static variable i, the constant k, and the static free function foo, all of which have internal connections. If you remove the static or const modifiers of these variables or functions, they will now multiply defined symbols errors when connected, and they conflict with global variables and global functions in a.cpp.
This article is from the "very blog" blog, make sure to keep this source http://10093949.blog.51cto.com/10083949/1714778
The 4th example--c++ internal links and external links