default initialization
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. |
Fournit la valeur initiale par défaut pour un nouvel objet .
Original:
Provides the default initial value to a new object.
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
T object ;
|
(1) | ||||||||
new T ;
|
(2) | ||||||||
[modifier] Explication
Initialisation par défaut est effectuée dans trois situations:
Original:
Default initialization is performed in three situations:
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.
1)
quand une variable avec la durée de stockage automatique est déclarée sans initialisation
Original:
when a variable with automatic storage duration is declared with no initializer
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)
quand un objet avec la durée de stockage dynamique est créée par une nouvelle expression sans un initialiseur
Original:
when an object with dynamic storage duration is created by a new-expression without an initializer
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)
quand une classe de base ou un membre non statique de données n'est pas mentionné dans un liste d'initialisation constructeur et que le constructeur est appelé .
Original:
when a base class or a non-static data member is not mentioned in a constructor liste d'initialisation and that constructor is called.
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 effets de l'initialisation par défaut sont les suivants:
Original:
The effects of default initialization are:
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.
- Si
T
est un type de classe, le constructeur par défaut est appelé à fournir la valeur initiale pour le nouvel objet .Original:IfT
is a class type, the constructeur par défaut is called to provide the initial value for the new object.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Si
T
est un type tableau, chaque élément du tableau est initialisé par défaut .Original:IfT
is an array type, every element of the array is default-initialized.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Sinon, rien n'est fait .Original:Otherwise, nothing is done.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si
T
est un type const-qualifié, il doit être d'un type classe avec un constructeur par défaut fourni par l'utilisateur .Original:
If
T
is a const-qualified type, it must be a class type with a user-provided default constructor.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] Notes
Initialisation par défaut de non-classe des variables avec la durée de stockage automatique et dynamique produit des objets avec des valeurs indéterminées (objets statiques et fil-locale se zéro initialisé)
Original:
Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-locale objects get zéro initialisé)
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.
Référence ne peut pas être initialisé par défaut .
Original:
Reference cannot be default-initialized.
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
#include <string> struct T1 {}; class T2 { int mem; public: T2() {} // "mem" not in initializer list }; int n; // This is not default-initialization, the value is zero. int main() { int n; // non-class: the value is undeterminate std::string s; // calls default ctor, the value is "" (empty string) std::string a[2]; // calls default ctor, creates two empty strings // int& r; // error: default-initializing a reference // const int n; // error: const non-class type // const T1 nd; // error: const class type with implicit ctor T1 t1; // ok, calls implicit default ctor const T2 t2; // ok, calls the user-provided default ctor // t2.mem is default-initialized }