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. |
Proporciona el valor inicial por defecto a un objeto nuevo .
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.
Contenido |
[editar] Sintaxis
T object ;
|
(1) | ||||||||
new T ;
|
(2) | ||||||||
[editar] Explicación
Inicialización por defecto se realiza en tres situaciones:
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)
cuando una variable con el tiempo de almacenamiento automático se declara sin inicializador
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)
cuando un objeto con una duración de almacenamiento dinámico es creado por una nueva expresión sin un inicializador
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)
cuando una clase base o un miembro no estático datos no se menciona en un inicializador lista constructor y que el constructor se llama .
Original:
when a base class or a non-static data member is not mentioned in a constructor inicializador 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.
Los efectos de la inicialización por defecto son:
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
es un tipo de clase, la default constructor está llamada a proporcionar el valor inicial para el nuevo objeto .Original:IfT
is a class type, the default constructor 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
es un tipo de matriz, cada elemento de la matriz es inicializada por defecto .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.
- De lo contrario, no se hace nada .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
es un tipo const cualificado, debe ser un tipo de clase con un constructor predeterminado proporcionado por el usuario .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.
[editar] Notas
Inicialización por defecto de la no-clase variables con el tiempo de almacenamiento automático y dinámico produce objetos con valores indeterminados (objetos estáticos e hilo locale-get cero inicializado)
Original:
Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-locale objects get cero inicializado)
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.
Referencia no puede ser inicializado por defecto .
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.
[editar] Ejemplo
#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 }