# Namespace aliases

> C++ Atlas: `cppatlas.com/w/cpp/language/namespace_alias` | Source: https://en.cppreference.com/w/cpp/language/namespace_alias | Domain: Language | Standards: C++11

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

## Official Specification Summary (cppreference)

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.

### Syntax

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

### 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.

### Keywords

`namespace`

### Example

```cpp
#include <iostream>

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

namespace fbz = foo::bar::baz;

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

Output:

```text
42
```

### See also

- [namespace declaration](https://en.cppreference.com/w/cpp/language/namespace): identifies a namespace
- [type alias declaration (C++11)](https://en.cppreference.com/w/cpp/language/type_alias): creates a synonym for a type

---
Attribution: content from https://en.cppreference.com/w/cpp/language/namespace_alias (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.