名前空間
変種
操作

new expression

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
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.
フロー制御
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.
条件付き実行文
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.
繰り返し文
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.
文をジャンプします
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.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
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)
指定子
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指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
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
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
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.
new expression
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
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.
明示 (C++11)
静的
特殊なメンバ関数
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.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
動的に取得したメモリ内のオブジェクトを初期化します.
Original:
Initializes objects in dynamically obtained memory.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
データが動的に割り当てられる必要がある場合に使用される、それはコンパイル前にその大きさを知らず、です.
Original:
Used where data need to be allocated dynamically, that is, without knowing its size prior the compilation.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 構文

::(オプション) new  type [array_n](オプション) (init_params)(オプション) (1)
::(オプション) new (type ) [array_n](オプション) (init_params)(オプション) (2)
::(オプション) new (placement_params)  type [array_n](オプション) (init_params)(オプション) (3)
::(オプション)    new      (placement_params)     (type )     [array_n](オプション)     (init_params)(オプション)     (4)
すべてのバージョンが型のオブジェクトを返す' 'タイプ*.
Original:
All versions return an object of type type *.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 説明

new式は、メモリー領域が割り当てられそこには、単一のオブジェクト、またはオブジェクトの配列を初期化し、最初に構築されたオブジェクトへのポインタを返します。それはコンストラクタを明示的に呼び出すコールするそうでなければ不可能であるため、式は動的にオブジェクトを構築するための唯一の方法です.
Original:
The new expression allocates a memory area, initializes either single object, or an array of objects there and returns a pointer to the first constructed object. Since it is not otherwise possible to call explicitly call a constructor, the expression is the only way to construct an object dynamically.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
式の最初の2つ、最後の2つのバージョンのみが文法的に異なる。動作は同じです.
Original:
The first two and last two versions of the expression differ only syntactically. The behavior is the same.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] メモリの割り当て

メモリが配分機能によって割り当てられ、どちらoperator newまたはoperator new[].
Original:
The memory is allocated by an 配分機能, either operator new or operator new[].
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
式の最後の2つのバージョンが呼ばれています' '配置newと資源配分機能に追加のパラメータを(placement_params)を渡すために使用され.
Original:
The last two versions of the expression are called placement new and are used to pass additional parameters (placement_params) to the allocation function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
array_nが存在しない場合は、メモリがoperator new割り当て関数を呼び出すことによって、単一のオブジェクトに割り当てられている。さもなければarray_nオブジェクトの配列のためのメモリがoperator new[]割り当て関数を呼び出すことによって割り当てられます。なお、size_of(以上type) *array_nので(この情報は適切に配列内のオブジェクト破壊するために必要とされるので、配列のサイズなど、)コンパイラによってコードの追加情報が割り当てられる可能性があります.
Original:
If array_n is absent, memory is allocated for a single object by invoking operator new allocation function. Otherwise memory for an array of array_n objects is allocated by calling operator new[] allocation function. Note, that more than size_of( type ) * array_n might be allocated because of additional information encoded by the compiler (such as the size of the array, since this information is needed in order to destruct the objects in the array properly).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
割り当て関数の名前はまずローカルクラスタイプスコープで検索され、検索が失敗した場合にのみ、グローバルな名前空間が検索されます。 ::new式中に存在する場合、唯一のグローバルな名前空間が検索されます。関数のプロトタイプは、選択するアロケーション機能するためには、次のようになります
Original:
The allocation function's name is firstly looked up in the local class type scope and only if the lookup fails, the global namespace is looked up. If :: is present in the new expression, only the global namespace is looked up. The prototype of the function should look like the following in order to the allocation function to be selected:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
void* operator new  (size_t count);
for versions 1, 2, array_n is not present
void* operator new[](size_t count);
for versions 1, 2, array_n is present
void* operator new  (size_t count/*, placement_params...*/);
for versions 3, 4 (placement new), array_n is not present
void* operator new[](size_t count/*, placement_params...*/);
for versions 3, 4 (placement new), array_n is present
count割り当てるバイト数、placement_paramsは配置式に与えられたパラメータである.
Original:
count is number of bytes to allocate, placement_params are the parameters given to the placement new expression.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[編集] デフォルトの実装およびオーバーロード
いくつかのデフォルトの割り当て関数は暗黙的に各翻訳単位で宣言されています。プログラムは、それらを明示的に実装されていない限り、また、暗黙の実装は、デフォルトでは、コンパイラによって提供されています。これらの関数は、(詳細はこのを参照)、次のとおりです
Original:
Several default allocation functions are implicitly declared in each translation unit. Also, implicit implementations are provided by the compiler by default, unless the program has explicitly implemented them. These functions are as follows (see この for more information):
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
void* operator new  (size_t);
(1)
void* operator new[](size_t);
(2)
void* operator new  (size_t, std::nothrow_t);
(3)
void* operator new[](size_t, std::nothrow_t);
(4)
void* operator new  (size_t, void* ptr);
(5)
void* operator new[](size_t, void* ptr);
(6)
1-2)
割り当ては、バイト数を要求したか失敗したかにstd::bad_allocをスローします
Original:
allocates requested number of bytes or throws std::bad_alloc on failure
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3-4)
割り当ては、バイト、あるいは失敗した返しNULLの数を要求され​​た
Original:
allocates requested number of bytes or returns NULL on failure
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5-6)
戻りptr。これは、ユーザが指定したメモリ領域にオブジェクトを構築することができます。プログラムは、これらの関数の明示的な実装を定義してはなりません.
Original:
returns ptr. This allows to construct an object in user-supplied memory area. The program must not define explicit implementations for these functions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] オブジェクトの初期化

array_nが存在しない場合は、1つのオブジェクトをコンストラクタにパラメータとしてinit_paramsを渡したり、それらが存在しない場合は、デフォルトのコンストラクタを呼び出し、取得したメモリ領域に初期化され.
Original:
If array_n is absent, single object is initialized in the acquired memory area, passing init_params as parameters to the constructor or invoking default constructor if they are not present.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
array_nが存在する場合は、array_nオブジェクトの配列は、各オブジェクトのコンストラクタにパラメータとしてinit_paramsを渡したりinit_paramsが存在しない場合、デフォルトのコンストラクタを呼び出すと、初期化され.
Original:
If array_n is present, an array of array_n objects is initialized, passing init_params as parameters to the constructor of each object or invoking default constructor if init_params are not present.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] キーワード

new