Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Namespace aliases

      From cppreference.com
      <cpp‎ |language
       
       
      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
       
      Declarations
       

      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.

      Contents

      [edit]Syntax

      namespacealias_name =ns_name; (1)
      namespacealias_name =::ns_name; (2)
      namespacealias_name =nested_name::ns_name; (3)

      [edit]Explanation

      The new aliasalias_name provides an alternate method of accessingns_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]Keywords

      namespace

      [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]
      type alias declaration(C++11) creates a synonym for a type[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/language/namespace_alias&oldid=174520"

      [8]ページ先頭

      ©2009-2025 Movatter.jp