Namespaces
Variants

Namespace aliases

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Namespace aliases
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

Namespace-Aliase ermöglichen es dem Programmierer, einen alternativen Namen für einen Namespace zu definieren.

Sie werden häufig als praktische Abkürzung für lange oder tief verschachtelte Namensräume verwendet.

Inhaltsverzeichnis

Syntax

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

Erklärung

Das neue Alias alias_name bietet eine alternative Methode zum Zugriff auf ns_name .

alias_name muss ein zuvor nicht verwendeter Name sein. alias_name ist für die Dauer des Gültigkeitsbereichs gültig, in dem es eingeführt wird.

Schlüsselwörter

namespace

Beispiel

#include <iostream>
namespace foo
{
    namespace bar
    {
         namespace baz
         {
             int qux = 42;
         }
    }
}
namespace fbz = foo::bar::baz;
int main()
{
    std::cout << fbz::qux << '\n';
}

Ausgabe:

42

Siehe auch

namespace declaration identifiziert einen Namespace
type alias declaration (C++11) erstellt ein Synonym für einen Typ