<div class="t-tr-text">operador<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">Original:</div><div class="t-tr-dropdown-orig">operator</div><div class="t-tr-dropdown-notes">The text has been machine-translated via [http://translate.google.com Google Translate].<br/> You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.</div></div></div></div></div> new<div class="t-tr-text">, Operador<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">Original:</div><div class="t-tr-dropdown-orig">, operator</div><div class="t-tr-dropdown-notes">The text has been machine-translated via [http://translate.google.com Google Translate].<br/> You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.</div></div></div></div></div> new[]
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <new>
|
||
| void* operator new ( std::size_t count ); |
(1) | |
| void* operator new[]( std::size_t count ); |
(2) | |
| void* operator new ( std::size_t count, const std::nothrow_t& ); |
(3) | |
| void* operator new[]( std::size_t count, const std::nothrow_t& ); |
(4) | |
| void* operator new ( std::size_t, void* ptr ); |
(5) | |
| void* operator new[]( std::size_t, void* ptr ); |
(6) | |
Asigna solicitado número de bytes. Estas funciones de asignación son llamados por nuevas expresiones- asignar memoria en el que nuevo objeto se inicializa .
1-2) Original:
Allocates requested number of bytes. These allocation functions are called by nuevas expresiones- to allocate memory in which new object would then be 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.
Asigna
3-4) count bytes de memoria libre. Llama al puntero de función que devuelve std::get_new_handler en caso de error y repite los intentos de asignación hasta nuevo controlador no vuelve o se convierte en un puntero nulo, momento en el cual arroja std::bad_alloc .Original:
Allocates
count bytes from free store. Calls the function pointer returned by std::get_new_handler on failure and repeats allocation attempts until new handler does not return or becomes a null pointer, at which time throws std::bad_alloc.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.
Igual que el 1-2, pero devuelve un puntero nulo cuando se std::bad_alloc 1-2 tiro
5-6) Original:
Same as 1-2, but returns a null pointer when 1-2 would throw std::bad_alloc
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.
no hace nada,
ptr devoluciones. Estas versiones son llamados por la nueva expresión que construir objetos en el almacenamiento asignado previamente .Original:
does nothing, returns
ptr. These versions are called by new-expression which construct objects in previously allocated storage.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.
Contenido |
[editar] Sustitución y sobrecarga
Las versiones 1-4) se declara implícitamente en cada unidad de traducción, incluso si el encabezado
<new> no está incluido. Estas funciones son reemplazables': proporcionado por el usuario no miembro de función con la misma firma que sustituye a la versión implícita. A lo sumo una sustitución puede ser proporcionado para cada una de las cuatro funciones de asignación implícita. Además, el programa puede definir versiones de miembro de clase de estas funciones o definir las funciones de asignación con firmas diferentes (excepto en que no se permite a reemplazar (5-6) las versiones de la función de asignación). La firma añadido debe ser similar a la siguiente, donde count es el número de bytes a asignar y placement_params' son los parámetros especificados para la expresión new:Original:
The versions 1-4) are implicitly declared in each translation unit even if the
<new> header is not included. These functions are replaceable: a user-provided non-member function with the same signature replaces the implicit version. At most one replacement may be provided for each of the four implicit allocation functions. Also, program can define class member versions of these functions or define allocation functions with different signatures (except that it is not permitted to replace (5-6) versions of the allocation function). The added signature should look like the following, where count is number of bytes to allocate and placement_params are the parameters supplied to the 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.
| void* operator new (size_t count/*, placement_params*/); |
for the new version |
|
| void* operator new[](size_t count/*, placement_params*/); |
for the new[] version |
|
La función de asignación se puede sustituir / sobrecargado de dos maneras:
Original:
The allocation function can be replaced/overloaded in two ways:
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.
- 'En el ámbito global': para llamarlo, la firma de las funciones de asignación sobrecargado debe ser visible en el lugar de asignación, salvo implícitamente declaradas funciones predeterminadas de asignación. Esta función de asignación se utiliza para todas las asignaciones con parámetros correspondientes en el programa actualOriginal:in the global scope: in order to call it, the signature of the overloaded allocation functions must be visible at the place of allocation, except for implicitly declared default allocation functions. This allocation function will be used for all allocations with corresponding parameters in the current programThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 'En el ámbito local': el
operator newsobrecargado debe ser miembro público static function de la clase. Esta función de asignación se utilizará únicamente para la asignación de esa clase particular .Original:in the local scope: the overloadedoperator newmust be static public member function of the class. This allocation function will be used only for allocations of that particular class.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Durante la compilación, cada expresión
new mira el nombre de la función adecuada asignación de una parte en el ámbito de la clase y después de que en el ámbito global. Puede ser instruidos para saltarse el primer paso llamando new como ::new. Tenga en cuenta, que según sobrecarga de reglas, las funciones de asignación declarada en el ámbito de clase oculta todas las funciones de asignación globales. Para obtener más información NJ expresión ver. Nota, que no es posible colocar en función de asignación de un espacio de nombres .Original:
During compilation, each
new expression looks up for appropriate allocation function's name firstly in the class scope and after that in the global scope. It can be instructed to skip the first step by calling new as ::new. Note, that as per sobrecarga de reglas, any allocation functions declared in class scope hides all global allocation functions. For more information see NJ expresión. Note, that it is not possible to place allocation function in a namespace.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.
[editar] Parámetros
| count | - | número de bytes para asignar
Original: number of bytes to allocate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| ptr | - | puntero a un área de memoria para inicializar el objeto a
Original: pointer to a memory area to initialize the object at The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[editar] Valor de retorno
1-4)puntero al área de memoria asignada
Original:
pointer to allocated memory area
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.
5-6) ptr
[editar] Excepciones
1-2)std::bad_alloc lanza en la falta de asignación de memoria
3-6)
Original:
throws std::bad_alloc on failure to allocate 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.
[editar] Ver también
| funciones desasignación Original: deallocation functions The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función) | |
| (C++11) |
obtiene el nuevo controlador actual Original: obtains the current new handler The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función) |
| registra un controlador nuevo Original: registers a new handler The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función) | |
| Obtiene el almacenamiento sin inicializar Original: obtains uninitialized storage The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función) | |
| asigna memoria Original: allocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función) | |