Implicit conversions
Da 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. |
As conversões implícitas são realizadas sempre que uma expressão de alguns
T1
tipo é usado em contexto que não aceita esse tipo, mas aceita algumas T2
outro tipo, nomeadamente:Original:
Implicit conversions are performed whenever an expression of some type
T1
is used in context that does not accept that type, but accepts some other type T2
, in particular: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.
- Quando a expressão é usada como argumento ao chamar uma função que é declarada com
T2
como parâmetro.Original:When the expression is used as the argument when calling a function that is declared withT2
as parameter.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Quando a expressão é utilizada como um operando com um operador que espera
T2
Original:When the expression is used as an operand with an operator that expectsT2
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Ao inicializar um novo objeto de
T2
tipo, incluindoreturn
declaração em umT2
função retornando.Original:When initializing a new object of typeT2
, includingreturn
statement in a function returningT2
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Quando a expressão é usada em uma instrução
switch
(T2
é do tipo integral)Original:When the expression is used in aswitch
statement (T2
is integral type)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Quando a expressão é usada em uma instrução
if
ou um circuito fechado (T2
é bool)Original:When the expression is used in anif
statement or a loop (T2
is bool)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
O programa é bem-formado (compila) somente se existe uma inequívoca' seqüência de conversão implícita de
T1
para T2
. Original:
The program is well-formed (compiles) only if there exists one unambiguous implicit conversion sequence from
T1
to T2
. 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.
Se existem várias sobrecargas da função ou operador de ser chamado, após a seqüência de conversão implícita é construído a partir de T1 a cada T2 disponíveis, as regras resolução de sobrecarga decidir qual sobrecarga é compilado.
Original:
If there are multiple overloads of the function or operator being called, after the implicit conversion sequence is built from T1 to each available T2, resolução de sobrecarga rules decide which overload is compiled.
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.
Índice |
[editar] Ordem das conversões
Seqüência de conversão implícita consiste no seguinte, nesta ordem:
Original:
Implicit conversion sequence consists of the following, in this order:
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.
1)
zero ou um' sequência padrão de conversão
Original:
zero or one standard conversion sequence
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)
zero ou um' conversão definida pelo usuário
Original:
zero or one user-defined conversion
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.
3)
zero ou uma sequência de conversão padrão
Original:
zero or one standard conversion sequence
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.
Ao considerar o argumento para um construtor ou para uma função definida pelo usuário de conversão, somente uma seqüência de conversão padrão é permitido (de outra forma definidos pelo usuário conversões poderia ser efetivamente em cadeia). Quando a conversão de um tipo embutido para outro tipo interno, apenas uma sequência de conversão de padrão é permitido.
Original:
When considering the argument to a constructor or to a user-defined conversion function, only one standard conversion sequence is allowed (otherwise user-defined conversions could be effectively chained). When converting from one built-in type to another built-in type, only one standard conversion sequence is allowed.
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.
Uma seqüência de conversão padrão consiste no seguinte, nesta ordem:
Original:
A standard conversion sequence consists of the following, in this order:
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.
1)
zero ou um' transformação lvalue
Original:
zero or one lvalue transformation
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)
zero ou uma promoção numérico ou' conversão numérica
Original:
zero or one numeric promotion or numeric conversion
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.
3)
zero ou um' ajuste qualificação
Original:
zero or one qualification adjustment
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.
A conversão definida pelo usuário consiste em:
Original:
A user-defined conversion consists of:
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.
@ * @ Zero ou um não-explícita construtor argumento único ou não explícita chamada função de conversão
Original:
@*@ zero or one non-explicit single-argument constructor or non-explicit conversion function call
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.
Uma
e
expressão é dito ser implicitamente conversível T2
se e só se o T2 t=e; declaração é bem formado (pode ser compilado), para alguns t
inventado temporária. Note-se que esta é diferente da T2 t(e), onde construtores explícitos e funções de conversão que, adicionalmente, ser considerado.Original:
An expression
e
is said to be implicitly convertible to T2
if and only if the declaration T2 t=e; is well-formed (can be compiled), for some invented temporary t
. Note that this is different from T2 t(e), where explicit constructors and conversion functions would additionally be considered.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.
Uma exceção é a regra acima é a conversão implícita especial invocado em cinco contextos (desde C++11), onde bool tipo é esperado:
Original:
One exception is the above rule is the special implicit conversion invoked in the following five contexts (desde C++11), where type bool is expected:
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.
- expressão controle de
if
,while
,for
Original:controlling expression ofif
,while
,for
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - os operadores lógicos
!
,&&
e||
Original:the logical operators!
,&&
and||
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
?:
o operador condicionalOriginal:the conditional operator?:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
static_assert
-
noexcept
-
em tais contextos, seqüência de conversão implícita é construído se o bool t(e); declaração é bem formado. isto é, a função de conversão explícita definido pelo utilizador, tais como
explicit T::operator bool() const;
é considerado. e
tal expressão é dito ser contextualmente conversível para bool.Original:
in such contexts, implicit conversion sequence is built if the declaration bool t(e); is well-formed. that is, the explicit user-defined conversion function such as
explicit T::operator bool() const;
is considered. Such expression e
is said to be contextually convertible to bool.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] Transformações lvalue
Transformações lvalue são aplicadas quando lvalue argumento (por exemplo, referência a um objecto) é utilizada no contexto em que rvalue (por exemplo, um número) é esperado.
Original:
Lvalue transformations are applied when lvalue argument (e.g. reference to an object) is used in context where rvalue (e.g. a number) is expected.
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] Lvalue para rvalue conversão
A glvalue de qualquer função não-,
T
tipo matriz não pode ser convertido implicitamente em prvalue do mesmo tipo. Se T
é um tipo não-classe, essa conversão também remove CV-eliminatórias. A menos que encontrou em contexto não avaliada (em um operando de sizeof, typeid, noexcept, ou decltype), esta conversão efetivamente cópia constrói um objeto temporário do tipo T
usando o glvalue original como o argumento do construtor, e que objeto temporário é retornado como um prvalue. Se o glvalue tem a std::nullptr_t tipo, o prvalue resultante é o nullptr
ponteiro nulo constante.Original:
A glvalue of any non-function, non-array type
T
can be implicitly converted to prvalue of the same type. If T
is a non-class type, this conversion also removes cv-qualifiers. Unless encountered in unevaluated context (in an operand of sizeof, typeid, noexcept, or decltype), this conversion effectively copy-constructs a temporary object of type T
using the original glvalue as the constructor argument, and that temporary object is returned as a prvalue. If the glvalue has the type std::nullptr_t, the resulting prvalue is the null pointer constant nullptr
.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] Matriz para conversão de ponteiro
Um lvalue ou rvalue do tipo "matriz de
N
T
" ou "conjunto de desconhecido ligou do T
" pode ser convertido implicitamente em uma prvalue do tipo "ponteiro para T
". O ponteiro resultante refere-se ao primeiro elemento da matriz.Original:
A lvalue or rvalue of type "array of
N
T
" or "array of unknown bound of T
" can be implicitly converted to a prvalue of type "pointer to T
". The resulting pointer refers to the first element of the array.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] Função para ponteiro
Um lvalue de
T
tipo de função pode ser implicitamente convertido para um ponteiro prvalue para essa função. Isto não se aplica a funções não-membro estático porque lvalues que se referem a funções não-membros estáticos não existem.Original:
An lvalue of function type
T
can be implicitly converted to a prvalue pointer to that function. This does not apply to non-static member functions because lvalues that refer to non-static member functions do not exist.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] Promoções numéricos
[editar] Promoção integral
Prvalues de pequenos tipos integrantes (tais como char) pode ser convertido para prvalues de maiores tipos integrais (como int). Em particular, operadores aritméticos não aceitam tipos menor do que int como argumentos e promoções integrais são aplicadas automaticamente. Esta conversão sempre preserva o valor.
Original:
Prvalues of small integral types (such as char) may be converted to prvalues of larger integral types (such as int). In particular, operadores aritméticos do not accept types smaller than int as arguments, and integral promotions are automatically applied. This conversion always preserves the value.
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.
As seguintes conversões implícitas são classificados como promoções integrais:
Original:
The following implicit conversions are classified as integral promotions:
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.
signed char
signed short
ou podem ser convertidos em int.Original:signed char
orsigned short
can be converted to int.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unsigned char
unsigned short
ou podem ser convertidos em unsigned int.Original:unsigned char
orunsigned short
can be converted to unsigned int.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
char
pode ser convertido para int unsigned int ou, dependendo do tipo de base: signed char ou unsigned char (ver acima)Original:char
can be converted to int or unsigned int depending on the underlying type: signed char or unsigned char (see above)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wchar_t
,char16_t
, echar32_t
pode ser convertido para o tipo primeira da lista a seguir capaz de manter sua escala de valor: int, unsigned int, long, unsigned long, long long, unsigned long long.Original:wchar_t
,char16_t
, andchar32_t
can be converted to the first type from the following list able to hold their entire value range: int, unsigned int, long, unsigned long, long long, unsigned long long.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Uma enumeração sem escopo tipo cujo tipo subjacente não é fixo pode ser convertido para o tipo primeira da lista a seguir capaz de manter a sua gama de valor: int, unsigned int, long, unsigned long, long long, ou unsigned long long. Se o intervalo de valores é maior, há promoções integrais aplicar.Original:An unscoped enumeration type whose underlying type is not fixed can be converted to the first type from the following list able to hold their entire value range: int, unsigned int, long, unsigned long, long long, or unsigned long long. If the value range is greater, no integral promotions apply.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Uma enumeração sem escopo tipo cujo tipo subjacente é fixo pode ser convertido para o seu tipo promovido subjacente. (desde C++11)Original:An unscoped enumeration type whose underlying type is fixed can be converted to its promoted underlying type. (desde C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Um tipo' bitfield pode ser convertido para int se pode representar gama de valor do campo de bits, caso contrário, a unsigned int se pode representar gama de valor do campo de bits, caso contrário, não se aplicam promoções integrais.Original:A bitfield type can be converted to int if it can represent entire value range of the bitfield, otherwise to unsigned int if it can represent entire value range of the bitfield, otherwise no integral promotions apply.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- O bool tipo pode ser convertido para o valor com int false tornando 0 e true tornando 1.Original:The type bool can be converted to int with the value false becoming 0 and true becoming 1.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
[editar] Flutuando promoção ponto
A prvalue de float tipo pode ser convertida para prvalue de double tipo. O valor não muda.
Original:
A prvalue of type float can be converted to prvalue of type double. The value does not change.
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] Conversões numéricas
Ao contrário das promoções, conversões numéricas podem alterar os valores, com a potencial perda de precisão.
Original:
Unlike the promotions, numeric conversions may change the values, with potential loss of precision.
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] Conversões integrais
A prvalue de um tipo de número inteiro ou de um tipo de enumeração sem escopo pode ser convertido em qualquer outro tipo de número inteiro. Se a conversão estiver listado em promoções integrais, é uma promoção e não a conversão.
Original:
A prvalue of an integer type or of an unscoped enumeration type can be converted to any other integer type. If the conversion is listed under integral promotions, it is a promotion and not a conversion.
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.
- Se o tipo de destino não está assinada, o valor resultante é o valor modulo 2n
onde n é o número de bits usados para representar o tipo de destino. Em aritmética complemento de 2 (usado em todas as plataformas onde compiladores C + + estão disponíveis), essa conversão é um não-op, exceto para o truncamento se o tipo de destino é pequeno.Original:If the destination type is unsigned, the resulting value is the value modulo 2n
where n is the number of bits used to represent the destination type. In 2's complement arithmetic (used on all platforms where C++ compilers are available), this conversion is a no-op, except for the truncation if the destination type is to small.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Se o tipo de destino é assinado, o valor não muda se o inteiro fonte pode ser representado no tipo de destino. Caso contrário, o resultado é definida pela implementação.Original:If the destination type is signed, the value does not change if the source integer can be represented in the destination type. Otherwise the result is implementation-defined.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Se o tipo de fonte é bool, o false valor é convertido em zero e o valor true é convertido para o valor do tipo de destino (nota de que, se o tipo de destino é int, este é um número inteiro de promoção, e não uma conversão inteiro)Original:If the source type is bool, the value false is converted to zero and the value true is converted to the value one of the destination type (note that if the destination type is int, this is an integer promotion, not an integer conversion)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Se o tipo de destino é bool, esta é uma conversão booleano (ver abaixo)Original:If the destination type is bool, this is a boolean conversion (see below)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
[editar] Flutuando conversões de ponto
A prvalue de um tipo de ponto flutuante podem ser convertidos em prvalue de qualquer tipo de ponto flutuante de outro. Se a conversão estiver listado em vírgula flutuante promoções, que é uma promoção e não a conversão.
Original:
A prvalue of an floating-point type can be converted to prvalue of any other floating-point type. If the conversion is listed under floating-point promotions, it is a promotion and not a conversion.
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.
- Se o valor-fonte pode ser representado exatamente no tipo de destino, isso não muda.Original:If the source value can be represented exactly in the destination type, it does not change.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Se o valor de origem é entre dois valores representáveis do tipo de destino, o resultado é um desses dois valores (que é definida pela implementação qual)Original:If the source value is between two representable values of the destination type, the result is one of those two values (it is implementation-defined which one)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Caso contrário, o comportamento é indefinido.Original:Otherwise, the behavior is undefined.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
[editar] Flutuante - conversões integrais
- A prvalue de tipo de ponto flutuante podem ser convertidos em prvalue de qualquer tipo inteiro. A parte fracionária é truncada, isto é, a parte fracionária é descartado. Se o valor não pode se encaixar no tipo de destino, o comportamento é indefinido. Se o tipo de destino é bool, esta é uma conversão booleano (ver a seguir).Original:A prvalue of floating-point type can be converted to prvalue of any integer type. The fractional part is truncated, that is, the fractional part is discarded. If the value can not fit into the destination type, the behavior is undefined. If the destination type is bool, this is a boolean conversion (see below).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Um tipo de enumeração prvalue de número inteiro ou sem escopo pode ser convertido para prvalue de qualquer tipo de ponto flutuante. Se o valor não pode ser representado corretamente, é a implementação definido se o mais próximo maior ou o mais próximo menor valor representável será selecionado. Se o valor não pode se encaixar no tipo de destino, o comportamento é indefinido. Se o tipo de fonte é bool, o false valor é convertido em zero, e o valor true é convertido para um.Original:A prvalue of integer or unscoped enumeration type can be converted to prvalue of any floating-point type. If the value can not be represented correctly, it is implementation defined whether the closest higher or the closest lower representable value will be selected. If the value can not fit into the destination type, the behavior is undefined. If the source type is bool, the value false is converted to zero, and the value true is converted to one.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
[editar] Conversões de ponteiro
- O ponteiro nulo' NULL constante ou em qualquer outra prvalue do tipo integral, que avalia a zero ou qualquer prvalue de std::nullptr_t tipo, incluindo o ponteiro nulo' nullptr literal, pode ser convertido para qualquer tipo de ponteiro, e o resultado é o valor do ponteiro nulo do tipo. Tal conversão (conhecido como 'ponteiro nulo conversão é permitida a conversão tot um tipo cv qualificado como uma única conversão, ou seja, não é considerado uma combinação de dados numéricos e de qualificação conversões).Original:The null pointer constant NULL or any other prvalue of integral type that evaluates to zero or any prvalue of type std::nullptr_t, including the null pointer literal nullptr, can be converted to any pointer type, and the result is the null pointer value of that type. Such conversion (known as 'null pointer conversion is allowed to conver tot a cv-qualified type as a single conversion, that is, it's not considered a combination of numeric and qualifying conversions).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Um ponteiro prvalue a qualquer (opcionalmente cv qualificado)
T
tipo de objeto pode ser convertido para um ponteiro prvalue a (idêntica cv qualificado) void. SeT
não é o tipo de tempo de execução do objecto pontiagudo, para, o ponteiro resultante é ajustado para apontar para o início da armazenagem ocupado pelo objecto mais derivado. Se o ponteiro original é um valor de ponteiro nulo, o resultado é um valor de ponteiro nulo do tipo de destino.Original:A prvalue pointer to any (optionally cv-qualified) object typeT
can be converted to a prvalue pointer to (identically cv-qualified) void. IfT
is not the runtime type of the pointed-to object, the resulting pointer is adjusted to point to the start of the storage occupied by the most-derived object. If the original pointer is a null pointer value, the result is a null pointer value of the destination type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Um ponteiro para um prvalue (opcionalmente cv qualificado) tipo de classe derivada pode ser convertido para prvalue ponteiro para sua classe base acessível, inequívoca (idêntica cv-qualificado). O resultado da conversão é um ponteiro para a classe base subobjeto dentro do objeto pontiagudo para. O valor de ponteiro nulo é convertido para o valor de ponteiro nulo do tipo de destino.Original:A prvalue pointer to a (optionally cv-qualified) derived class type can be converted to prvalue pointer to its accessible, unambiguous (identically cv-qualified) base class. The result of the conversion is a pointer to the base class subobject within the pointed-to object. The null pointer value is converted to the null pointer value of the destination type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
[editar] Ponteiro-para-membro conversões
- O ponteiro nulo' NULL constante ou em qualquer outra prvalue do tipo integral, que avalia a zero ou qualquer prvalue de std::nullptr_t tipo, incluindo o ponteiro nulo' nullptr literal, pode ser convertido para qualquer tipo de ponteiro-para-membro, e o resultado é o valor de ponteiro nulo desse tipo. Tal conversão (conhecido como 'ponteiro nulo conversão é permitida a conversão tot um tipo cv qualificado como uma única conversão, ou seja, não é considerado uma combinação de dados numéricos e de qualificação conversões).Original:The null pointer constant NULL or any other prvalue of integral type that evaluates to zero or any prvalue of type std::nullptr_t, including the null pointer literal nullptr, can be converted to any pointer-to-member type, and the result is the null pointer value of that type. Such conversion (known as 'null pointer conversion is allowed to conver tot a cv-qualified type as a single conversion, that is, it's not considered a combination of numeric and qualifying conversions).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Prvalue ponteiro para o membro de algum tipo
T
numB
classe de base pode ser convertido para prvalue ponteiro para o membro doT
mesmo tipo na suaD
classe derivada. SeB
é inacessível, ambíguo, ou base virtual deD
ou é uma base de alguma base intermediária virtual deD
, a conversão é mal-formado (não compilar). O ponteiro resultante pode ser dereferenced com um objetoD
, e ele vai acessar o membro dentro da base de subobjetoB
desse objetoD
. O valor de ponteiro nulo é convertido para o valor de ponteiro nulo do tipo de destino.Original:Prvalue pointer to member of some typeT
in a base classB
can be converted to prvalue pointer to member of the same typeT
in its derived classD
. IfB
is inaccessible, ambiguous, or virtual base ofD
or is a base of some intermediate virtual base ofD
, the conversion is ill-formed (won't compile). The resulting pointer can be dereferenced with aD
object, and it will access the member within theB
base subobject of thatD
object. The null pointer value is converted to the null pointer value of the destination type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
[editar] Conversões booleanos
Prvalues de integrais, tipos de ponto flutuante de enumeração, sem escopo, de ponteiro, e ponteiro-para-membro pode ser convertido para prvalues de bool tipo.
Original:
Prvalues of integral, floating-point, unscoped enumeration, pointer, and pointer-to-member types can be converted to prvalues of type bool.
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.
O valor zero (para contagem integral, de ponto flutuante, e sem escopo) eo ponteiro nulo e os nulos ponteiro-para-membro valores tornam-se false. Todos os outros valores se true.
Original:
The value zero (for integral, floating-point, and unscoped enumeration) and the null pointer and the null pointer-to-member values become false. All other values become true.
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.
Prvalue de std::nullptr_t tipo, incluindo
nullptr
, pode ser convertido para prvalue de bool tipo. O valor resultante é false. (desde C++11)Original:
Prvalue of type std::nullptr_t, including
nullptr
, can be converted to prvalue of type bool. The resulting value is false. (desde C++11)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] Conversões de qualificação
- Um ponteiro de tipo de prvalue ao tipo <div class="t-tr-text">cv-qualificadosOriginal:cv-qualifiedThe text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.T
pode ser convertido para prvalue ponteiro para um tipo mais cv qualificado mesmaT
(em outras palavras, podem ser adicionados constness)Original:A prvalue of type pointer tocv-qualificados</div> typeOriginal:cv-qualifiedThe text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.T
can be converted to prvalue pointer to a more cv-qualified same typeT
(in other words, constness can be added)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- A prvalue de tipo ponteiro para membro do cv qualificado
T
tipo emX
classe pode ser convertido para prvalue ponteiro para membro deT
mais cv tipo qualificado na classeX
.Original:A prvalue of type pointer to member of cv-qualified typeT
in classX
can be converted to prvalue pointer to member of more cv-qualified typeT
in classX
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
"Mais" CV-qualificados que isso significa
Original:
"More" cv-qualified means that
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.
- ' Tipo não qualificado pode ser convertido para
const
Original:unqualified type can be converted toconst
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ' Tipo não qualificado pode ser convertido para
volatile
Original:unqualified type can be converted tovolatile
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ' Tipo não qualificado pode ser convertido para
const volatile
Original:unqualified type can be converted toconst volatile
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
const
tipo pode ser convertida paraconst volatile
Original:const
type can be converted toconst volatile
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
volatile
tipo pode ser convertida paraconst volatile
Original:volatile
type can be converted toconst volatile
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
Para multi-nível ponteiros, as seguintes restrições:
Original:
For multi-level pointers, the following restrictions apply:
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.
A
0 qualificado ponteiro para cv1
1 qualificado ponteiro para... cv1
n-1 qualificado ponteiro para cv1
n qualificado
0 qualificado ponteiro para cv2
1 qualificado ponteiro para... cv2
n-1 qualificado ponteiro para cv2
n qualificado
P1
ponteiro multinível que é cv10 qualificado ponteiro para cv1
1 qualificado ponteiro para... cv1
n-1 qualificado ponteiro para cv1
n qualificado
T
é conversível para uma P1
ponteiro multinível que é cv20 qualificado ponteiro para cv2
1 qualificado ponteiro para... cv2
n-1 qualificado ponteiro para cv2
n qualificado
T
somente seOriginal:
A multilevel pointer
0-qualified pointer to cv1
1-qualified pointer to ... cv1
n-1-qualified pointer to cv1
n-qualified
0-qualified pointer to cv2
1-qualified pointer to ... cv2
n-1-qualified pointer to cv2
n-qualified
P1
which is cv10-qualified pointer to cv1
1-qualified pointer to ... cv1
n-1-qualified pointer to cv1
n-qualified
T
is convertible to a multilevel pointer P1
which is cv20-qualified pointer to cv2
1-qualified pointer to ... cv2
n-1-qualified pointer to cv2
n-qualified
T
only ifThe 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.
- O número de níveis
n
é o mesmo para ambos os ponteirosOriginal:The number of levelsn
is the same for both pointersThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se houver um const na qualificação cv1
k em algum nível (excepto nível zero) de P1, há uma const no cv2
k mesmo nível de P2Original:If there is a const in the cv1
k qualification at some level (other than level zero) of P1, there is a const in the same level cv2
k of P2The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se houver um volatile na qualificação cv1
k em algum nível (excepto nível zero) de P1, há uma volatile no mesmo cv2
klevel de P2Original:If there is a volatile in the cv1
k qualification at some level (other than level zero) of P1, there is a volatile in the same cv2
klevel of P2The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se em algum nível
k
O CV-qualificações são diferentes entreP1
eP2
, então deve haver um const em cada nível único (que não seja de nível zero) deP2
até k: cv2
1, cv2
2 ... cv2
k.Original:If at some levelk
the cv-qualifications are different betweenP1
andP2
, then there must be a const at every single level (other than level zero) ofP2
up until k: cv2
1, cv2
2 ... cv2
k.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - As mesmas regras se aplicam a multi-nível de ponteiros para os membros e multi-nível ponteiros misturados a objetos e ponteiros para membros.Original:Same rules apply to multi-level pointers to members and multi-level mixed pointers to objects and pointers to members.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Nível zero é tratado pela regulamentação para a conversão de vários níveis de qualificação não.Original:Level zero is addressed by the rules for non-multilevel qualification conversions.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
Em particular, isto impede a conversão da
T**
para const T**
, mas a conversão para const T* const*
é permitido.Original:
In particular, this forbids the conversion from
T**
to const T**
, but conversion to const T* const*
is allowed.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] O problema de segurança bool
Até a introdução de funções de conversão explícitas em C + +11, criando uma classe que deve ser utilizável em contextos booleanos (por exemplo if(obj) { ... apresentou um problema: dada uma função definida pelo usuário de conversão, como T::operator bool() const;, a seqüência de conversão implícita permitiu uma norma adicional sequência de conversão depois de que a chamada da função, o que significa que o bool resultante pode ser convertido para int, permitindo que o código como obj << 1; ou int i=test;.
Original:
Until the introduction of explicit conversion functions in C++11, designing a class that should be usable in boolean contexts (e.g. if(obj) { ... presented a problem: given a user-defined conversion function, such as T::operator bool() const;, the implicit conversion sequence allowed one additional standard conversion sequence after that function call, which means the resultant bool could be converted to int, allowing such code as obj << 1; or int i=test;.
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.
Uma solução inicial para este pode ser visto na std::basic_ios, que define operator! e operator void*()(até C++11), de modo que o código como if(std::cin) {... compila porque void* é conversível para bool, mas int n = std::cout; não compila porque void* não é conversível para int. Isso ainda permite que o código absurdo como delete std::cout; para compilar, e muitos pré-C + 11 bibliotecas de terceiros foram projetados com um mais elaborada solução, conhecida como a Safe Bool idiom.
Original:
One early solution for this can be seen in std::basic_ios, which defines operator! and operator void*()(até C++11), so that the code such as if(std::cin) {... compiles because void* is convertible to bool, but int n = std::cout; does not compile because void* is not convertible to int. This still allows nonsense code such as delete std::cout; to compile, and many pre-C++11 third party libraries were designed with a more elaborate solution, known as the Safe Bool idiom.
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.