C++ › Namespaces

What is an inline namespace and what is it used for?

Advanced

Answer

An inline namespace's members are treated as if they were in the enclosing namespace (accessible without the inner qualifier), while still being distinct for linkage/ABI. It's primarily used for library versioning: a library can put its current API in an inline namespace (e.g., v2) so users write ns::name but the symbols are versioned for ABI compatibility.
namespace lib {
    inline namespace v2 { void f(); }
}
lib::f();   // resolves to lib::v2::f
Real-world example A library exposes lib::f while internally versioning symbols via inline namespaces for ABI stability.

Common follow-ups: How does it aid versioning? | Do users need the inner qualifier?