C++

Namespaces

11 question(s)

How do namespaces interact with the one-definition rule and linkage?

Advanced
A fully-qualified name is unique across the program, so the same name in different namespaces are distinct entities with separate linkage—avoiding ODR violations that identical global names would cause. Anonymous namespaces give internal linkage (per translation unit), while named-namespace entities generally have external linkage unless otherwise specified.
Real-world example Placing two same-named helper types in different namespaces avoids an ODR clash at link time.

Common follow-ups: How do namespaces avoid ODR clashes? | What linkage do anonymous namespaces give?

Compilation & Linking Namespaces Namespaces