new expression
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
動的に取得したメモリ内のオブジェクトを初期化します.
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.
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.
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
This section is incomplete Reason: Explanation about how types are specified is missing |
[編集]メモリの割り当て
メモリが配分機能によって割り当てられ、どちらoperator newまたはoperator new[].
Original:
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つのバージョンが呼ばれています' '配置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.
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.
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.
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.
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.
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) | |
割り当ては、バイト数を要求したか失敗したかにstd::bad_allocをスローします
3-4) 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.
You can help to correct and verify the translation. Click here for instructions.
割り当ては、バイト、あるいは失敗した返しNULLの数を要求された
5-6) 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.
You can help to correct and verify the translation. Click here for instructions.
戻り
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.