default initialization
Aus 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. |
Bietet die Standard-Ausgangswert zu einem neuen Objekt .
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.
Inhaltsverzeichnis |
[Bearbeiten]Syntax
Tobject; | (1) | ||||||||
new T; | (2) | ||||||||
[Bearbeiten]Erklärung
Default-Initialisierung ist in drei Situationen durchgeführt:
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)
wenn eine Variable mit automatischer Lagerdauer wird ohne Initialisierung deklariert
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)
wenn ein Objekt mit dynamischen Lagerdauer wird durch einen neuen Ausdruck ohne Initialisierung erstellt
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)
wenn eine Basisklasse oder ein nicht-statisches Datenelement nicht in einem Konstruktor Initialisierungsliste erwähnt und dass Konstruktor aufgerufen wird .
Original:
when a base class or a non-static data member is not mentioned in a constructor Initialisierungsliste 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.
Die Auswirkungen der Default-Initialisierung sind:
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.
- Wenn
T
eine Klasse-Typ ist, wird die Standardkonstruktor aufgerufen, um den ursprünglichen Wert für das neue Objekt bietet .Original:IfT
is a class type, the Standardkonstruktor 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.
- Wenn
T
ein Array-Typ ist, ist jedes Element des Arrays standardmäßig initialisiert .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.
- Ansonsten wird nichts getan .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.
Wenn
T
a const qualifizierten Typ ist, muss es eine Klasse-Typ mit einem vom Benutzer bereitgestellten Standardkonstruktor sein .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.
[Bearbeiten]Notes
Standard Initialisierung nicht Klassenvariablen mit automatischer und dynamischer Lagerdauer produziert Objekten mit unbestimmter (statische und Faden-locale Objekte erhalten Null initialisiert)
Original:
Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-locale objects get Null initialisiert)
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.
Referenz nicht default-initialisiert werden .
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.
[Bearbeiten]Beispiel
#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 undeterminatestd::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 ctorconst T2 t2;// ok, calls the user-provided default ctor // t2.mem is default-initialized}