Nested Inline Namespaces In C++20 Last Updated : 11 Nov, 2023 Comments Improve Suggest changes Like Article Like Report 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. Prerequisite: C++ Inline Namespaces, C++ Namespace Nesting. 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 } }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. Example The following example demonstrates the use of the new syntax of nested inline namespaces in C++: C++ // C++ Program to illustrate the use of new nested inline // namespace syntax #include <iostream> namespace old_parent_ns { inline old_nested_ns1 { namespace old_nested_ns2 { void func() { std::cout << "Function from Old Defintion\n"; } } } } // declaring same namespace using new definition syntax namespace new_parent_ns ::inline new_nested_ns1 :: new_nested_ns2 { void func() { std::cout << "Function from New Definition"; } } // driver code int main() { old_parent::old_nested_ns2::func(); new_parent::new_nested_ns2::func(); return 0; } Output Function from Old Defintion Function from New Definition As we can see, both of the definition works the same. It depends upon our requirement which one we want to use. Comment More infoAdvertise with us Next Article Nested Inline Namespaces In C++20 M maha123 Follow Improve Article Tags : C++ Geeks Premier League Geeks Premier League 2023 Practice Tags : CPP Similar Reads Can namespaces be nested in C++? In C++, namespaces can be nested, and resolution of namespace variables is hierarchical. For example, in the following code, namespace inner is created inside namespace outer, which is inside the global namespace. In the line "int z = x", x refers to outer::x. If x would not have been in outer then 2 min read Namespace in C++ Name conflicts in C++ happen when different parts of a program use the same name for variables, functions, or classes, causing confusion for the compiler. To avoid this, C++ introduce namespace.Namespace is a feature that provides a way to group related identifiers such as variables, functions, and 6 min read Inline Variables in C++ 17 An inline variable in C++ is a variable that is declared using an inline specifier. It is an exception to one definition having multiple definitions across various translation units. Inline variables have an external linkage when not declared as static. Syntaxinline data_type variable_name = initial 3 min read namespace in C++ | Set 2 (Extending namespace and Unnamed namespace) We have introduced namespaces in below set 1.Namespace in C++ | Set 1 (Introduction) Defining a Namespace: A namespace definition begins with the keyword namespace followed by the namespace name as follows: namespace namespace_name {// code declarations i.e. variable (int a;)method (void add();)clas 4 min read Nested list in C++ STL list in STL is used to represent a linked list in C++. How to create a nested list. We are given n lists, we need to create a list of n lists. Examples: Input : Number of lists: 2 1st list: {1 2} 2nd list: {3 4 5 6} Output : [ [ 1 2 ] [ 3 4 5 6 ] ] Input : Number of lists: 3 1st list : {0 1} 2nd lis 2 min read Cons of using the whole namespace in C++ A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organise code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. P 2 min read What is Docker Namespaces? Namespaces have been part of the Linux kernel since around 2002, with more functionality and namespace types introduced over time. Real container functionality was added to the Linux kernel in 2013, however. This is what makes namespaces useful and popular. Namespaces enable you to create an isolate 4 min read C++ Inline Namespaces and Usage of the "using" Directive Inside Namespaces Prerequisite: Namespaces in C++ In C++, namespaces can be nested, and the resolution of namespace variables is hierarchical. An inline namespace is a namespace that uses the optional keyword inline in its original-namespace definition. This allows the identifiers of the nested inline namespace to be 3 min read Nested Classes in C++ A nested class is a class which is declared in another enclosing class. A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules shall be obeyed. For example, p 2 min read How to use :: Namespace Alias Qualifier in C# Namespace Alias Qualifier(::) makes the use of alias name in place of longer namespace and it provides a way to avoid ambiguous definitions of the classes. It is always positioned between two identifiers. The qualifier looks like two colons(::) with an alias name and the class name. It can be global 2 min read Like