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. |
<metanoindex/>
Fournit la valeur initiale par dfaut 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.
Syntaxe
T object ;
|
(1) | ||||||||
new T ;
|
(2) | ||||||||
Explication
Initialisation par dfaut est effectue 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 dure de stockage automatique est dclare 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 dure de stockage dynamique est cre 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 donnes 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 dfaut 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
Test un type de classe, le constructeur par dfaut est appel fournir la valeur initiale pour le nouvel objet .Original:IfTis a class type, the constructeur par dfaut 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
Test un type tableau, chaque lment du tableau est initialis par dfaut .Original:IfTis 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 dfaut 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.
Notes
Initialisation par dfaut de non-classe des variables avec la dure de stockage automatique et dynamique produit des objets avec des valeurs indtermines (objets statiques et fil-locale se zro 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 zro 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.
Rfrence ne peut pas tre initialis par dfaut .
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.
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
}