C++ namespace Nested Namespaces

Introduction

Remember how we said we could have nested namespaces? We can put a namespace into another namespace.

We used the following the nest namespaces:

namespace MyNameSpace1 
{ 
    namespace MyNameSpace2 
    { //from w  ww .ja  v  a 2  s.c  om
        namespace MyNameSpace3 
        { 
            // some code 
        } 
    } 
} 

The C++17 standard allows us to nest namespaces using the namespace resolution operator.

The above example can now be rewritten as:

namespace MyNameSpace1::MyNameSpace2::MyNameSpace3 
{ 
    // some code 
} 



PreviousNext

Related