Namespace
Varianti

default initialization

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Controllo del flusso
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dichiarazioni esecuzione condizionale
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterazione dichiarazioni
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Vai dichiarazioni
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche (deprecato)
noexcept specificatore (C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Specifiers
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv specificatori
Durata di stoccaggio specificatori
constexpr specificatore (C++11)
specificatore auto (C++11)
alignas specificatore (C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Tipo alias dichiarazione (C++11)
attributi (C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della memoria
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
esplicito (C++11)
statico
Funzioni membro speciali
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni (C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
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.

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.
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.
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.
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.
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.
  • Se T è un tipo di classe, il costruttore di default è chiamato a fornire il valore iniziale per il nuovo oggetto.
    Original:
    If T 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:
    If T 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.

[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.
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.

[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
}


[modifica] Vedi anche