Espaços nominais
Variantes
Acções

new expression

Da cppreference.com
< cpp‎ | language

 
 
Linguagem C + +
Tópicos gerais
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.
Controle de fluxo
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.
Declarações execução condicional
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.
Instruções de iteração
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.
Ir declarações
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.
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaração da função
lambda declaração da função
modelo de função
linha especificador
especificações de exceção (obsoleta)
noexcept especificador (C++11)
Exceções
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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)
Especificadores
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 especificadores
armazenamento duração especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialização
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literais
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressões
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representações alternativas
Utilitários
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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
tipo de alias declaração (C++11)
atributos (C++11)
Lança
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversões implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Elenco C-estilo e funcional
Alocação de memória
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
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classe propriedades específicas de função
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.
Funções membro especiais
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.
Modelos
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
modelo de classe
modelo de função
especialização de modelo
pacotes de parâmetros (C++11)
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Assembly embutido
 
Inicializa os objetos na memória dinamicamente obtido.
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.
Usado onde os dados precisam ser alocados de forma dinâmica, isto é, sem saber o seu tamanho antes da compilação.
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.

Índice

[editar] Sintaxe

::(opcional) new  type [array_n](opcional) (init_params)(opcional) (1)
::(opcional) new (type ) [array_n](opcional) (init_params)(opcional) (2)
::(opcional) new (placement_params)  type [array_n](opcional) (init_params)(opcional) (3)
::(opcional)    new      (placement_params)     (type )     [array_n](opcional)     (init_params)(opcional)     (4)
Todas as versões retornar um objeto do tipo' 'tipo *.
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.

[editar] Explicação

A expressão new aloca uma área de memória, inicializa ou único objeto, ou um array de objetos lá e retorna um ponteiro para o primeiro objeto construído. Como não é possível de outra forma de chamar explicitamente chamar um construtor, a expressão é a única maneira de construir um objeto dinamicamente.
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.
As duas primeiras e última duas versões da expressão só diferem sintaticamente. O comportamento é o mesmo.
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.

[editar] Alocação de memória

A memória é alocada por um função de alocação, seja operator new ou operator new[].
Original:
The memory is allocated by an função de alocação, 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.
As últimas duas versões da expressão são chamados' 'nova colocação e são utilizados para transmitir os parâmetros adicionais (placement_params) para a função de distribuição.
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.
Se array_n está ausente, a memória é alocada para um único objeto, invocando operator new função de alocação. Caso contrário memória para uma matriz de objetos array_n é alocado chamando operator new[] função de alocação. Note que, mais do que size_of( type ) * array_n pode ser alocada por causa da informação adicional codificada pelo compilador (tais como o tamanho da matriz, uma vez que esta informação é necessária, a fim de destruir os objetos na matriz adequadamente).
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.
O nome da função de alocação está em primeiro lugar procurado no local de classe' tipo de escopo e somente se a pesquisa falhar, o espaço global é procurado. Se :: está presente na expressão new, somente o namespace global está olhou para cima. O protótipo da função deve ser semelhante à seguinte para a função de alocação a ser selecionados:
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 é o número de bytes a serem alocados, placement_params são os parâmetros determinados para a colocação expressão' novo.
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.
[editar] Implementações padrão e sobrecarga
Várias funções de alocação padrão são implicitamente declarados em cada unidade de tradução. Além disso, as implementações implícitas são fornecidos pelo compilador por padrão, a menos que o programa foi implementado explicitamente eles. Estas funções são as seguintes (ver este para mais informações):
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 este 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)
aloca solicitado número de bytes ou joga std::bad_alloc em caso de falha
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)
aloca solicitado número de bytes ou NULL retornos em caso de falha
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 retornos. Isto permite a construção de um objeto em fornecido pelo usuário área de memória. O programa não deve definir implementações explícitas para essas funções.
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.

[editar] Inicialização do objeto

Se array_n está ausente, único objeto é inicializado na área de memória adquirida, passando init_params como parâmetros para o construtor ou invocando construtor padrão se eles não estiverem presentes.
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.
Se array_n está presente, um array de objetos array_n é inicializado, passando init_params como parâmetros para o construtor de cada objeto ou invocar construtor padrão se init_params não estão presentes.
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.

[editar] Palavras-chave

new