Namespaces
De 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. |
Les espaces de noms fournissent un procédé pour éviter les conflits de noms dans les grands projets .
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.
Les symboles déclarés à l'intérieur d'un bloc d'espace de noms sont placés dans un champ nommé qui les empêche d'être confondus avec des symboles de noms identiques dans d'autres portées .
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.
Des déclarations multiples d'espaces de noms avec le même nom sont autorisés, cette définition multiple entraîne la création d'un espace de noms unique comprenant tous les symboles de toutes ces déclarations .
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.
Sommaire |
[modifier] Syntaxe
namespace ns_nom { déclarations }
|
(1) | ||||||||
inline namespace ns_nom { déclarations }
|
(2) | (depuis C++11) | |||||||
namespace { déclarations }
|
(3) | ||||||||
ns_name:: nom
|
(4) | ||||||||
using namespace ns_nom;
|
(5) | ||||||||
using ns_nom:: nom;
|
(6) | ||||||||
namespace ns_nom = ns_nom_bien_trop_long;
|
(7) | ||||||||
namespace ns_nom:: ns_nom_2:: ns_nom_3 { déclarations }
|
(8) | (depuis C++17) | |||||||
[modifier] Explication
This section is incomplete |
1)
Déclaration de l'espace de noms ns_nom
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.
2)
Déclaration de l'espace de noms ns_nom. Les définitions apparaîtront à la fois à l'intérieur de ns_nom et dans l'espace de noms l'incluant
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.
3) Définition d'espace de nom anonyme. Les définitions d'un tel espace de noms n'apparaîtront que dans jusqu'à la fin de l'unité de traduction et ont une liaison interne.
4)
Façon standard d'accéder au contenu d'un espace de noms .
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.
5)
Rendre tous les symboles d'un espace de noms accessible dans le champ d'application de la directive 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.
6)
Rendre un des symboles spécifiques d'un espace de noms accessible dans le champ d'application de la directive 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.
7) Définition d'un alias d'espace de noms, ici ns_nom est un synonyme de ns_nom_bien_trop_long.
8) Définition d'espace de noms inclus, namespace A::B::C { est équivalent à namespace A { namespace B { namespace C {
[modifier] Exemple
Cet exemple montre comment utiliser un espace de noms pour créer une classe qui a déjà été nommé dans l'espace de noms
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; // Vecteur de la librairie standard. vec::vector<int> v2; // Vecteur définit par l'utilisateur. v1 = v2; // Errerr: v1 et v2 sont deux type d'objet différent { using namespace std; vector<int> v3; // Semblable à l'utilisation de std::vector v1 = v3; // OK } { using vec::vector; vector<int> v4; // Semblable à l'utilisation de vec::vector v2 = v4; // OK } return 0; }
[modifier] Voir aussi
alias d'espace de noms | crée un alias d'un espace de noms existant
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. |