default initialization
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Fornisce il valore iniziale di default per un nuovo oggetto.
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.
Indice |
[modifica] Sintassi
T object ;
|
(1) | ||||||||
new T ;
|
(2) | ||||||||
[modifica] Spiegazione
Inizializzazione di default viene eseguita in tre situazioni:
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)
quando una variabile con la durata di archiviazione automatica è dichiarata senza inizializzatore
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)
quando un oggetto con durata di stoccaggio dinamico viene creato un nuovo-espressione senza un inizializzatore
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)
Quando una classe base o un membro non statico dati non è menzionato in un inizializzatore lista costruttore e che il costruttore si chiama.
Original:
when a base class or a non-static data member is not mentioned in a constructor inizializzatore lista 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.
Gli effetti di inizializzazione di default sono:
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.
- Se
T
è un tipo di classe, il costruttore di default è chiamato a fornire il valore iniziale per il nuovo oggetto.Original:IfT
is a class type, the costruttore di default 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.
- Se
T
è un tipo di matrice, ogni elemento della matrice è default-inizializzato.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.
- In caso contrario, non si fa nulla.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.
Se
T
è un const tipo qualificato, deve essere un tipo di classe con un fornito dall'utente costruttore di default.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.
[modifica] Note
Inizializzazione di default di non di classe variabili con durata di memorizzazione automatica e dinamica produce oggetti con valori indeterminati (oggetti statici e filo-locale ottenere azzerare inizializzato)
Original:
Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-locale objects get azzerare inizializzato)
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.
Di riferimento non può essere inizializzato di default.
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.
[modifica] Esempio
#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 }