C++20 Nested Inline Namespaces Syntax

In C++ 20, we can define the Nested Inline Namespaces like:

namespace my_namespace :: inline nested_namespace {
        // Members of nested_namespace
}

The new syntax is much easier to manage and implement.

Nested Inline Namespaces In C++20

The Inline Namespace is a feature that was first introduced in C++ 11. They can also be nested inside another namespace and the members of this nested namespace can be accessed as if they are the members of the parent namespace.

Their syntax may seem complex so in C++20, a new version introduced a new syntax for declaring/defining Nested Inline Namespaces which makes them more flexible and expressive.

Traditional Syntax (C++11 to C++17)

In earlier versions, the inline namespaces were defined as:

namespace my_namespace {
        inline namespace nested_namespace {
                // Members of nested_namespace
        }
}

Similar Reads

C++20 Nested Inline Namespaces Syntax

In C++ 20, we can define the Nested Inline Namespaces like:...

Example

The following example demonstrates the use of the new syntax of nested inline namespaces in C++:...

Contact Us