Namespaces
来自cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
命名空間提供了一種方法,以防止在大型工程項目的名稱衝突.
Original:
Namespaces provide a method for preventing name conflicts in large projects.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
的命名空間塊內聲明的符號被放置在指定的範圍內,防止他們被誤認為是相同名稱的符號,在其它範圍內.
Original:
Symbols declared inside a namespace block are placed in a named scope that prevents them from being mistaken for identically-named symbols in other scopes.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
允許多個具有相同名稱的命名空間聲明,導致在一個命名空間包括所有這些聲明中所有的符號.
Original:
Multiple declarations of namespaces with the same name are allowed, resulting in a namespace including all symbols from all such declarations.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目錄 |
[编辑] 語法
namespace ns_name { declarations }
|
(1) | ||||||||
inline namespace ns_name { declarations }
|
(2) | (C++11 起) | |||||||
ns_name:: name
|
(3) | ||||||||
using namespace ns_name;
|
(4) | ||||||||
using ns_name:: name;
|
(5) | ||||||||
[编辑] 解釋
本節是不完整的 |
#聲明的命名空間name.
Original:
# Declaration of the namespace name.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#聲明的命名空間name。定義將同時顯示的內name,包含它的命名空間
Original:
# Declaration of the namespace name. Definitions will appear both inside name and its enclosing namespace
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#標準方式訪問命名空間中的內容.
Original:
# Standard way of accessing namespace content.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#所有符號訪問的命名空間的using指令的範圍.....
Original:
# Making all symbols of a namespace accessible in the scope of the using directive.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#一個特定的符號訪問的命名空間的using指令的範圍.....
Original:
# Making a specific symbols of a namespace accessible in the scope of the using directive.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 為例
這個例子展示了如何使用一個命名空間創建一個類,它已經被命名為
std
命名空間中的.
Original:
This example shows how to use a namespace to create a class that already has been named in the
std
namespace.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <vector> namespace vec { template< typename T > class vector { // ... }; } // of vec int main() { std::vector<int> v1; // Standard vector. vec::vector<int> v2; // User defined vector. v1 = v2; // Error: v1 and v2 are different object's type. { using namespace std; vector<int> v3; // Same as std::vector v1 = v3; // OK } { using vec::vector; vector<int> v4; // Same as vec::vector v2 = v4; // OK } return 0; }
[编辑] 另請參閱
命名空間別名 | 現有的命名空間創建一個別名
Original: creates an alias of an existing namespace The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |