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

new expression

提供: 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
メモリ確保
new
クラス
クラス固有の関数特性
特別なメンバ関数
テンプレート
その他
 
動的に取得したメモリ内のオブジェクトを初期化します.
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

close