default initialization
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
新しいオブジェクトにデフォルトの初期値を提供しています.
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.
目次 |
[編集]構文
Tobject; | (1) | ||||||||
new T; | (2) | ||||||||
[編集]説明
デフォルトの初期化は、次の3つの状況で実行されます
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)
自動記憶域期間を持つ変数は初期化子を使用して宣言されたとき
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)
ダイナミック記憶域期間を持つオブジェクトが初期化せずに、新しい発現によって作成されたとき
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)
基底クラスまたは非静的データメンバはコンストラクタ初期化子リストに記載されていないと、そのコンストラクタが呼び出されたときに.
Original:
when a base class or a non-static data member is not mentioned in a constructor 初期化子リスト 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.
デフォルトの初期化の効果は、次のとおりです
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.
T
がクラス型ならば、デフォルトのコンストラクタですは、新しいオブジェクトの初期値を提供するために呼び出されます.Original:IfT
is a class type, the デフォルトのコンストラクタです 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.
T
が配列型である場合は、配列の各要素は、デフォルトで初期化され.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.
- それ以外の場合は、何も行われません.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.
T
がconst修飾型であれば、ユーザーが提供するデフォルトコンストラクタを持つクラス型でなければなりません.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.
[編集]ノート
自動かつ動的な記憶域期間を持つ非クラス変数のデフォルトの初期化は、不定値(静的およびスレッドロケールオブジェクトがゼロは初期化されますを取得する)を使ってオブジェクトを生成します
Original:
Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-locale objects get ゼロは初期化されます)
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.
リファレンスはデフォルト初期化することができません.
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.
[編集]例
Run this code
#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}