The Wayback Machine - https://web.archive.org/web/20180601055745/http://ja.cppreference.com:80/w/cpp/language/default_initialization
名前空間
変種
操作

default initialization

提供: cppreference.com
< cpp‎ | language

 
 
C++言語
一般的なトピック
フロー制御
条件付き実行文
繰り返し文 (ループ)
ジャンプ文
関数
関数宣言
ラムダ関数宣言
inline 指定子
例外指定(非推奨)
noexcept 指定子(C++11)
例外
名前空間
指定子
decltype(C++11)
auto(C++11)
alignas(C++11)
記憶域期間指定子
初期化
代替表現
リテラル
ブーリアン - 整数 - 浮動小数点
文字 - 文字列 - nullptr(C++11)
ユーザ定義(C++11)
ユーティリティ
属性(C++11)
typedef 宣言
型エイリアス宣言(C++11)
キャスト
暗黙の変換 - 明示的な変換
static_cast - dynamic_cast
const_cast - reinterpret_cast
メモリ確保
クラス
クラス固有の関数特性
特別なメンバ関数
テンプレート
その他
 
新しいオブジェクトにデフォルトの初期値を提供しています.
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.

目次

[編集]構文

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.
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.
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.
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.
デフォルトの初期化の効果は、次のとおりです
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.
  • Tが配列型である場合は、配列の各要素は、デフォルトで初期化され.
    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.
  • それ以外の場合は、何も行われません.
    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.

[編集]ノート

自動かつ動的な記憶域期間を持つ非クラス変数のデフォルトの初期化は、不定値(静的およびスレッドロケールオブジェクトがゼロは初期化されますを取得する)を使ってオブジェクトを生成します
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.
リファレンスはデフォルト初期化することができません.
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.

[編集]

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


[編集]参照

close