Déclaration d'une union
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. |
This section is incomplete Reason: Expand description and example |
Une union est un type de classe spéciale qui stocke l'ensemble de ses membres de données dans le même emplacement mémoire.
Original:
A union is a special class type that stores all of its data members in the same memory location.
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 unions ne peuvent pas avoir de fonctions virtuelles, ne peuvent être héritées ou hériter d'autres classes.
Original:
Unions cannot have virtual functions, be inherited or inherit other classes.
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 unions (avant C++11) ne peuvent contenir que les types BVD (bonnes vieilles données) .
Original:
(avant C++11) Unions can only contain POD (plaine anciennes données) types.
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.
(depuis C++11) Si une union contient un élément non-BVD, qui a une fonction particulière définie par l'utilisateur (constructeur, destructeur, constructeur par copie ou affectation par copie) cette fonction est supprimée par défaut dans l' union et doit être explicitement définie par l'utilisateur .
Original:
(depuis C++11) If a union contains a non-POD member, which has a user-defined special function (constructor, destructor, copy constructor or copy assignment) that function is deleted by default in the union and needs to be defined explicitly by the user.
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
union name { member_declarations } object_list (en option) ;
|
(1) | ||||||||
union { member_declarations } ;
|
(2) | ||||||||
[modifier] Explication
# Union nomée
Original:
#Named union
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.
# Union anonyme
Original:
#Anonymous union
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.
[modifier] Unions anonymes
Les membres d'une union anonyme sont accessibles à partir de la portée englobante comme des simples variables.
Original:
Members of an anonymous union are accessible from the enclosing scope as single variables.
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 unions anonymes ont d'autres restrictions: elles doivent seulement comporter des membres publiques et ne peuvent pas avoir des fonctions membres.
Original:
Anonymous unions have further restrictions: they must have only public members and cannot have member functions.
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 unions dans la portée d'un espace de noms doivent être statiques.
Original:
Namespace-scope anonymous unions must be static.
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.
[modifier] Exemple
Résultat :
comme int: 1024 comme char: 128
(Pour processeurs petit-boutistes)
Original:
(for little-endian processors)
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.