##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Namespace aliases

From cppreference.com
< cpp‎ | language

Namespace aliases allow the programmer to define an alternate name for a namespace.

They are commonly used as a convenient shortcut for long or deeply-nested namespaces.

### [edit] Syntax

`namespace` alias_name = ns_name`;` | (1) |
`namespace` alias_name = `::`ns_name`;` | (2) |
`namespace` alias_name = nested_name`::`ns_name`;` | (3) |

### [edit] Explanation

The new alias alias_name provides an alternate method of accessing ns_name.

alias_name must be a name not previously used. alias_name is valid for the duration of the scope in which it is introduced.

### [edit] Example

Run this code

    #include <iostream>

    namespace foo {
        namespace bar {
             namespace baz {
                 int qux = 42;
             }
        }
    }

    namespace fbz = foo::bar::baz;

    int main()
    {
        std::cout << fbz::qux << '\n';
    }

Output:

    42

### [edit] See also

namespace declaration | identifies a namespace[edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/language/namespace_alias&oldid=67707"