Search code examples
c++scopenamespacesnamespace-alias

What is the scope of a namespace alias?


Does a C++ namespace alias defined inside a function definition have a block, function, file, or other scope (duration of validity)?


Solution

  • It's a block duration of validity.

    For example: If you define a namespace alias as below, the namespace alias abc would be invalid outside the {...}-block.

    {  
        namespace abc = xyz;
        abc::test t;  //valid 
    }
    abc::test t;  //invalid