- Overview
- Table of Contents
- Special Member Functions: Constructors, Destructors, and the Assignment Operator
- Operator Overloading
- Memory Management
- Automatic Storage
- Static Storage Duration and Thread Storage Duration
- Dynamic Storage Duration
- POD (Plain Old Data) and NonPOD Objects
- malloc() and free() Versus new and delete
- Support for Object Semantics
- Safety
- Allocating and Deallocating Arrays Using new[] and delete[]
- Dealing with Exceptions
- Placement new
- Allocating Arrays Using Placement new
- Member Alignment
- Overriding new and delete
- Linkage Types
- Guidelines for Effective Memory Management
- Summary
- Online Resources
- Replacing new and delete Operators, Part I
- Replacing new and delete Operators, Part II
- Pointers FAQ
- Pointers FAQ, Part II
- Pointers FAQ, Part III
- Pointers FAQ, Part IV
- Five Ways to Improve Your App's Memory Management
- Templates
- Namespaces
- Time and Date Library
- Streams
- Object-Oriented Programming and Design Principles
- The Standard Template Library (STL) and Generic Programming
- Exception Handling
- Runtime Type Information (RTTI)
- Signal Processing
- Creating Persistent Objects
- Bit Fields
- New Cast Operators
- Environment Variables
- Variadic Functions
- Pointers to Functions
- Function Objects
- Pointers to Members
- Lock Files
- Design Patterns
- Dynamic Linking
- Tips and Techniques
- Five Things You Need to Know About C++11 Unions
- A Tour of C99
- A Tour of C1X
- C++0X: The New Face of Standard C++
- C++0x Concurrency
- The Reflecting Circle
- We Have Mail
- The Soapbox
- Numeric Types and Arithmetic
- Careers
- Locales and Internationalization
Linkage Types
Last updated Mar 1, 2004.
Objects, references, functions, types, templates, and namespaces are all considered names. A name can have one of three linkage types: external linkage, internal linkage, or no linkage. The linkage type of a name specifies its visibility from other scopes and translation units. A name with external linkage can be referred to from every translation unit of the program. Examples of such names include ordinary functions that aren't explicitly declared as static, global objects, const objects explicitly declared extern, classes, enumerations and their enumerators, templates, namespaces, and so on. Here are a few examples of names with external linkage:
int n; //global non-static, hence external linkage
class C
{
void f(); // member functions
static int n;// static data members
};
extern const K; //defined in a different translation unit
void func ();
namespace NS
{
class D{}; // qualified name NS::D has external linkage
}
enum DIR
{
Up,
Down
} // DIR, Up, and Down have external linkage
A name with internal linkage is visible only from within the translation unit in which it was declared. A name declared in a namespace scope (that is, declared globally or within a namespace) has internal linkage if it's the name of a static object, a static function, a member of an anonymous union, a member of an anonymous namespace, a typedef name, or a const object not declared extern. Here are some examples of names with internal linkage:
static void f(); //a static function
static int q; //a static object declared in global scope
namespace //members of anonymous namespace
{
class C{};
int x;
}
const M=1000; //const object not declared extern
union{ //members of an anonymous union
int x;
float y;
};
typedef int I; // typedef names
Names with no linkage are visible only in the scope in which they're declared. Such names include local objects, local classes, and other local types. Put differently, any name that has neither external linkage nor internal linkage has no linkage. Here are some examples of such names:
int main()
{
class C{}; // C is a local class; has no linkage
int j; // local object not declared extern has no linkage
C c; // the object c has no linkage
enum Parity // local enum and enumerators
{
Even,
Odd
};
}



