Other operators
![]() |
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. |
Operator name | Syntax | Overloadable | Prototype examples (for class T) | |
---|---|---|---|---|
Inside class definition | Outside class definition | |||
function call | a(a1, a2)
|
Yes | R T::operator()(Arg1 &a1, Arg2 &a2, ... ...); | N/A |
comma | a, b
|
Yes | T2& T::operator,(T2 &b); | T2& operator,(const T &a, T2 &b); |
conversion | (type) a | Yes | operator type() | N/A |
ternary conditional | a ? b : c
|
No | N/A | N/A |
Índice |
[editar] Explicação
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.
You can help to correct and verify the translation. Click here for instructions.
[editar] Built-in operador de chamada de função
E
, seguido de uma lista, possivelmente vazia de A1, A2, A3, ...
expressões, entre parênteses.E
, followed by a possibly empty list of expressions A1, A2, A3, ...
, in parentheses.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.
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.
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.
E
pode ser sobrecarregado, resolução de sobrecarga regras usadas para decidir qual é a sobrecarga de ser chamado.E
can be overloaded, resolução de sobrecarga rules used to decide which overload is to be called.You can help to correct and verify the translation. Click here for instructions.
E
especifica uma função de membro, ele pode ser virtual, caso em que o overrider final dessa função será chamada, usando o despacho dinâmico em tempo de execução.E
specifies a member function, it may be virtual, in which case the final overrider of that function will be called, using dynamic dispatch at runtime.You can help to correct and verify the translation. Click here for instructions.
A1
, A2
, A3
, etc, fornecidos como argumentos são avaliados de forma arbitrária, e cada parâmetro de função é inicializado com seu argumento correspondente após conversão implícita se necessário. Se a chamada for feita para uma função membro, o ponteiro this ao objeto atual é convertido como que por conversão explícita para o ponteiro this esperado pela função. A inicialização e destruição de cada um dos parâmetros ocorre no contexto do chamador, o que significa, por exemplo, que, se um parâmetro de construtor lança uma excepção, os manipuladores de exceção definidas na função, assim como um bloco de função-tente, não são considerados. Se a função é uma função de aridade, argumento promoções padrão são aplicadas a todos os argumentos encontrados pelo parâmetro reticências.A1
, A2
, A3
, etc, provided as arguments are evaluated in arbitrary order, and each function parameter is initialized with its corresponding argument after conversão implícita if neccessary. If the call is made to a member function, then the this pointer to current object is converted as if by explicit cast to the this pointer expected by the function. The initialization and destruction of each parameter occurs in the context of the caller, which means, for example, that if constructor of a parameter throws an exception, the exception handlers defined within the function, even as a function-try block, are not considered. If the function is a variadic function, argumento promoções padrão are applied to all arguments matched by the ellipsis parameter.You can help to correct and verify the translation. Click here for instructions.
virtual
) palavra-chave), mesmo que a função primordial que é realmente chamado retorna um tipo diferente. Isto permite que as funções primordiais para retornar ponteiros ou referências a classes que são derivadas a partir do tipo de retorno devolvida pela função de base, isto é, C + + suportes covariantes tipos de retorno). Se E
especifica um destrutor, o tipo de retorno é void.virtual
) keyword), even if the overriding function that's actually called returns a different type. This allows the overriding functions to return pointers or references to classes that are derived from the return type returned by the base function, i.e. C++ supports covariantes tipos de retorno). If E
specifies a destructor, the return type is void.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.
T
é o nome de um tipo.T
is the name of a type.You can help to correct and verify the translation. Click here for instructions.
#include <cstdio> struct S { int f1(double d) { printf("%f \n", d); // variable argument function call } int f2() { f1(7); // member function call, same as this->f1() // integer argument converted to double } }; void f() { puts("function called"); // function call } int main() { f(); // function call S s; s.f2(); // member function call }
Saída:
function called 7.000000
[editar] Built-in operador vírgula
E1
expressão é avaliada, o valor de retorno é descartado, e seus efeitos colaterais são concluídas antes da avaliação da expressão começa E2
(note que essa capacidade se perde com a definida pelo usuário operator,
). E1
is evaluated, its return value is discarded, and its side effects are completed before evaluation of the expression E2
begins (note that this ability is lost with user-defined operator,
). You can help to correct and verify the translation. Click here for instructions.
E2
.E2
.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.
Saída:
n = 2 m = 7
[editar] Built-in operador de conversão
expr
expressão e executa conversão explícita para o T
tipo. expr
and performs explicit cast to the type T
. 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] Operador condicional
You can help to correct and verify the translation. Click here for instructions.
LR operator?:(bool, L, R ); |
||
T operator?:(bool, T, T ); |
||
L
e R
. O operador ":?" Não pode ser sobrecarregado, essas assinaturas de função só existem com o propósito de resolução de sobrecarga.L
and R
. The operator “?:” cannot be overloaded, these function signatures only exist for the purpose of overload resolution.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.
You can help to correct and verify the translation. Click here for instructions.
E2
E3
(ou ambos) é um throw-expressão, o resultado do operador condicional é o resultado da expressão (não jogar) outro, e é um prvalue (após lvalue-to-rvalue, matriz-de-ponteiro ou função para ponteiro-conversão). Operador condicional como é comumente usado em constexpr programação.E2
or E3
(or both) is a throw-expression, the result of the conditional operator is the result of the other (not throw) expression, and is a prvalue (after lvalue-to-rvalue, array-to-pointer, or function-to-pointer conversion). Such conditional operator is commonly used in constexpr programação.You can help to correct and verify the translation. Click here for instructions.
E2
ou E3
são de void tipo, o resultado é um tipo de prvalue void.E2
or E3
are of type void, the result is a prvalue of type void.You can help to correct and verify the translation. Click here for instructions.
E2
e E3
têm tipos de classes diferentes (ou mesmo tipo com diferentes cv-qualificação) ea categoria mesmo valor. Neste caso, é feita uma tentativa para converter um (e apenas um) dos operandos com o tipo do outro, como se segue:E2
and E3
have different class types (or same type with different cv-qualification) and the same value category. In this case, an attempt is made to convert one (and only one) of the operands to the type of the other, as follows: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.
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.
You can help to correct and verify the translation. Click here for instructions.
E2
ou E3
são glvalues do mesmo tipo. Neste caso, o resultado tem o mesmo tipo e categoria valor.E2
or E3
are glvalues of the same type. In this case, the result has the same type and value category.You can help to correct and verify the translation. Click here for instructions.
E2
ou E3
tem tipo de classe: a resolução de sobrecarga é uma tentativa de selecionar a melhor conversão de um tipo para o outro.E2
or E3
has class type: overload resolution is attempted to select the best conversion from one type to the other.You can help to correct and verify the translation. Click here for instructions.
E2
nem E3
ter tipo de classe: primeiro, lvalue-a-rvalue, array para ponteiro, e função para-ponteiro conversões são aplicadas. Em seguida, E2
nor E3
have class type: first, lvalue-to-rvalue, array-to-pointer, and function-to-pointer conversions are applied. Then, You can help to correct and verify the translation. Click here for instructions.
E2
e E3
agora têm o mesmo tipo, o resultado é um prvalue temporária desse tipo, cópia inicializada a partir de qualquer operando foi selecionado depois de avaliar E1
E2
and E3
now have the same type, the result is a prvalue temporary of that type, copy-initialized from whatever operand was selected after evaluating E1
You can help to correct and verify the translation. Click here for instructions.
E2
e E3
têm aritmética ou tipo de enumeração: conversões aritméticas usuais são aplicados para trazê-los para o tipo comum, que é o tipo de resultado.E2
and E3
have arithmetic or enumeration type: usual arithmetic conversions are applied to bring them to common type, that type is the result.You can help to correct and verify the translation. Click here for instructions.
E2
e E3
são ponteiros, ou um ponteiro e uma constante nula, ou ambas as constantes de ponteiro nulo, um dos quais é um std::nullptr_t, em seguida, as conversões de ponteiro e convrsions qualificação são aplicados ao trazê-los ao tipo comum, que é o tipo de resultado.E2
and E3
are pointers, or a pointer and a null constant, or a both null pointer constants, one of which is a std::nullptr_t, then pointer conversions and qualification convrsions are applied to bring them to common type, that type is the result.You can help to correct and verify the translation. Click here for instructions.
E2
e E3
são ponteiros para membros, ou um ponteiro para membro e uma constante nula: então ponteiro-para-membro conversões e convrsions qualificação são aplicados para trazê-los para o tipo comum, que é o tipo E2
and E3
are pointers to members, or a pointer to member and a null constant: then pointer-to-member conversions and qualification convrsions are applied to bring them to common type, that type is the You can help to correct and verify the translation. Click here for instructions.
#include <string> #include <stdexcept> struct Node { Node* next; int data; // deep-copying copy constructor Node(const Node& other) : next(other.next ? new Node(*other.next) : NULL) , data(other.data) {} Node(int d) : next(NULL), data(d) {} ~Node() { delete next ; } }; int main() { // simple rvalue example int n = 1>2 ? 10 : 11; // 1>2 is false, so n = 11 // simple lvalue example int m = 10; (n == m ? n : m) = 7; // n == m is false, so m = 7 // throw example std::string str = 2+2==4 ? "ok" : throw std::logic_error("2+2 != 4"); }
[editar] Biblioteca padrão
operator()
a ser usado como função de objectos.operator()
to be used as function objects.You can help to correct and verify the translation. Click here for instructions.
Exclui o objeto ou matriz Original: deletes the object or array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::default_delete função pública membro)
| |
compara seus argumentos usando proprietário baseados em semântica Original: compares its arguments using owner-based semantics The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função) | |
retorna a soma de dois argumentos Original: returns the sum of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::plus função pública membro)
| |
retorna a diferença entre dois argumentos Original: returns the difference between two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::minus função pública membro)
| |
retorna o produto de dois argumentos Original: returns the product of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::multiplies função pública membro)
| |
devolve o resultado da divisão do primeiro argumento pelo segundo argumento Original: returns the result of the division of the first argument by the second argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::divides função pública membro)
| |
retorna o resto da divisão do primeiro argumento pelo segundo argumento Original: returns the remainder from the division of the first argument by the second argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::modulus função pública membro)
| |
retorna a negação do argumento Original: returns the negation of the argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::negate função pública membro)
| |
Verifica se os argumentos são iguais Original: checks if the arguments are equal The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::equal_to função pública membro)
| |
Verifica se os argumentos não são iguais Original: checks if the arguments are not equal The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::not_equal_to função pública membro)
| |
verifica se o primeiro argumento é maior do que o segundo Original: checks if the first argument is greater than the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::greater função pública membro)
| |
verifica se o primeiro argumento é menor que o segundo Original: checks if the first argument is less than the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::less função pública membro)
| |
verifica se o primeiro argumento é maior que ou igual à segunda Original: checks if the first argument is greater than or equal to the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::greater_equal função pública membro)
| |
verifica se o primeiro argumento é menor que ou igual à segunda Original: checks if the first argument is less than or equal to the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::less_equal função pública membro)
| |
retorna a lógica AND dos dois argumentos Original: returns the logical AND of the two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::logical_and função pública membro)
| |
retorna o OR lógico dos dois argumentos Original: returns the logical OR of the two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::logical_or função pública membro)
| |
retorna o NÃO lógico do argumento Original: returns the logical NOT of the argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::logical_not função pública membro)
| |
returns the result of bitwise AND of two arguments (of std::bit_and função pública membro)
| |
retorna o resultado de bitwise OR de dois argumentos Original: returns the result of bitwise OR of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::bit_or função pública membro)
| |
retorna o resultado de bitwise XOR de dois argumentos Original: returns the result of bitwise XOR of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::bit_xor função pública membro)
| |
retorna o complemento lógico de o resultado de uma chamada para o predicado armazenado Original: returns the logical complement of the result of a call to the stored predicate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::unary_negate função pública membro)
| |
retorna o complemento lógico de o resultado de uma chamada para o predicado armazenado Original: returns the logical complement of the result of a call to the stored predicate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::binary_negate função pública membro)
| |
chama a função armazenada Original: calls the stored function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::reference_wrapper função pública membro)
| |
lexicographically compares two strings using this locale's collate facet (of std::locale função pública membro)
| |
compara dois valores do tipo value_type Original: compares two values of type value_type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::map::value_compare função pública membro)
| |
compara dois valores do tipo value_type Original: compares two values of type value_type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::multimap::value_compare função pública membro)
| |
executa a função Original: executes the function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::packaged_task função pública membro)
| |
avanços do estado do motor e retorna o valor gerado Original: advances the engine's state and returns the generated value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::linear_congruential_engine função pública membro)
| |
gera o próximo número aleatório na distribuição Original: generates the next random number in the distribution The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::uniform_int_distribution função pública membro)
|
You can help to correct and verify the translation. Click here for instructions.
verifica se o valor é diferente de zero Original: checks if the value is non-zero The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::error_code função pública membro)
| |
verifica se o valor é diferente de zero Original: checks if the value is non-zero The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::error_condition função pública membro)
| |
acessa o elemento da bitset Original: accesses the element of the bitset The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::bitset::reference função pública membro)
| |
acessa o elemento do vector <bool> Original: accesses the element of the vector<bool> The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::vector<bool>::reference função pública membro)
| |
verifica se existe é associado objeto gerenciado Original: checks if there is associated managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::unique_ptr função pública membro)
| |
verifica se existe é associado objeto gerenciado Original: checks if there is associated managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::shared_ptr função pública membro)
| |
acessa a referência armazenada Original: accesses the stored reference The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::reference_wrapper função pública membro)
| |
converte o objeto em value_type , retorna value Original: converts the object to value_type , returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::integral_constant função pública membro)
| |
(até C++11) (desde C++11) |
verifica se não ocorreu nenhum erro (sinônimo de !fail()) Original: checks if no error has occurred (synonym of !fail()) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::basic_ios função pública membro)
|
converte para o tipo string subjacente Original: converts to the underlying string type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::sub_match função pública membro)
| |
carrega um valor de um objeto atômico Original: loads a value from an atomic object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::atomic função pública membro)
| |
testa se o bloqueio é dono da sua mutex associado Original: tests whether the lock owns its associated mutex The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::unique_lock função pública membro)
| |
converte o ponteiro conseguiu um ponteiro para tipo diferente Original: converts the managed pointer to a pointer to different type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (of std::auto_ptr função pública membro)
|
operator,
em boost.assign, boost.spirit, e outras bibliotecas.operator,
in boost.assign, boost.spirit, and other libraries.You can help to correct and verify the translation. Click here for instructions.
[editar] Veja também
Operadores comuns | ||||||
---|---|---|---|---|---|---|
assinamento | incremento descremento |
aritmético | lógico | comparação | acesso de membro |
outros |
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
Operadores Especiais | ||||||
static_cast converte um tipo a um outro tipo relacionado |