Increment/decrement operators
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. |
Incremento / decremento aumenta o disminuye el valor del objeto .
Original:
Increment/decrement operators increments or decrements the value of the object.
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.
| Operator name | Syntax | Overloadable | Prototype examples (for class T) | |
|---|---|---|---|---|
| Inside class definition | Outside class definition | |||
| pre-increment | ++a
|
Yes | T& T::operator++(); | T& operator++(T& a); |
| pre-decrement | --a
|
Yes | T& T::operator--(); | T& operator--(T& a); |
| post-increment | a++
|
Yes | T T::operator++(int); | T operator++(T& a, int); |
| post-decrement | a--
|
Yes | T T::operator--(int); | T operator--(T& a, int); |
| ||||
[editar] Explicación
Pre-incremento y' pre-decremento incrementos de los operadores o disminuye el valor del objeto y devuelve una referencia al resultado .
Original:
pre-increment and pre-decrement operators increments or decrements the value of the object and returns a reference to the result.
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.
' Post-incremento y decremento posterior' crea una copia del objeto, los incrementos o disminuciones del valor del objeto y devuelve la copia desde antes del incremento o decremento .
Original:
post-increment and post-decrement creates a copy of the object, increments or decrements the value of the object and returns the copy from before the increment or decrement.
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] Construido en operadores de prefijo
Para cada tipo aritmético opcionalmente volátiles calificado
A que no sea bool, y por cada P puntero opcionalmente volátiles calificado para el tipo de objeto opcionalmente cv-calificados, las firmas de función siguientes participar en la resolución de sobrecarga:Original:
For every optionally volatile-qualified arithmetic type
A other than bool, and for every optionally volatile-qualified pointer P to optionally cv-qualified object type, the following function signatures participate in overload resolution: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& operator++(A&) |
||
| bool& operator++(bool&) |
(obsoleto) | |
| P& operator++(P&) |
||
| A& operator--(A&) |
||
| P& operator--(P&) |
||
El operando de un prefijo de incremento incorporada o operador de decremento debe ser un valor-modificables (no constante referencia) de tipo aritmético no booleana o puntero para completar tipo de objeto. Para estos operandos, la ++x expresión es exactamente equivalente a x+=1, y la --x expresión es exactamente equivalente a x-=1, es decir, el resultado es el operando de la actualización, devuelven como valor-i, y todas las reglas de conversión aritméticas y reglas de la aritmética de puntero definido para aplicar operadores aritméticos .
Original:
The operand of a built-in prefix increment or decrement operator must be a modifiable lvalue (non-const reference) of non-boolean arithmetic type or pointer to complete object type. For these operands, the expression ++x is exactly equivalent to x+=1, and the expression --x is exactly equivalent to x-=1, that is, the result is the updated operand, returned as lvalue, and all arithmetic conversion rules and pointer arithmetic rules defined for operadores aritméticos 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.
Si el operando del operador preincremento es de bool tipo, se establece a true (obsoleto) .
Original:
If the operand of the preincrement operator is of type bool, it is set to true (obsoleto).
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] Construido en operadores de sufijo
Para cada tipo aritmético opcionalmente volátiles calificado
A que no sea bool, y por cada P puntero opcionalmente volátiles calificado para el tipo de objeto opcionalmente cv-calificados, las firmas de función siguientes participar en la resolución de sobrecarga:Original:
For every optionally volatile-qualified arithmetic type
A other than bool, and for every optionally volatile-qualified pointer P to optionally cv-qualified object type, the following function signatures participate in overload resolution: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 operator++(A&, int) |
||
| bool operator++(bool&, int) |
(obsoleto) | |
| P operator++(P&, int) |
||
| A operator--(A&, int) |
||
| P operator--(P&, int) |
||
El operando de un incremento incorporado en postfix o el operador de decremento debe ser un valor-modificables (no constante referencia) de tipo aritmético no booleana o puntero para completar tipo de objeto. El resultado es un prvalue, que es una copia del valor original del operando. Como un efecto secundario, este operador modifica el valor de su
arg argumento como por la evaluación de arg += 1 o arg -= 1, por incremento y decremento, respectivamente. Todas las reglas de conversión aritméticas y reglas aritméticas puntero definido para aplicar operadores aritméticos .Original:
The operand of a built-in postfix increment or decrement operator must be a modifiable lvalue (non-const reference) of non-boolean arithmetic type or pointer to complete object type. The result is a prvalue, which is a copy the original value of the operand. As a side-effect, this operator modifies the value of its argument
arg as if by evaluating arg += 1 or arg -= 1, for increment and decrement respectively. All arithmetic conversion rules and pointer arithmetic rules defined for operadores aritméticos 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.
Si el operando del operador postincremento es de bool tipo, se establece a true (obsoleto) .
Original:
If the operand of the postincrement operator is of type bool, it is set to true (obsoleto).
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] Ejemplo
#include <iostream> int main() { int n = 1; int n2 = ++n; int n3 = ++ ++n; int n4 = n++; // int n5 = n++ ++; // compile error // int n5 = n + ++n; // undefined behavior std::cout << "n = " << n << '\n' << "n2 = " << n2 << '\n' << "n3 = " << n3 << '\n' << "n4 = " << n4 << '\n'; }
Output:
n = 5 n2 = 2 n3 = 4 n4 = 4
[editar] Notas
Debido a los efectos secundarios que participan, una función de operadores de incremento y decremento se debe utilizar con cuidado para evitar un comportamiento indefinido debido a violaciónes de reglas de secuenciación .
Original:
Because of the side-effects involved, built-in increment and decrement operators must be used with care to avoid undefined behavior due to violations of reglas de secuenciación.
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.
Debido a que una copia temporal del objeto se construye durante la operación, pre-incremento o' pre-decremento operadores suelen ser más eficientes en contextos en los que el valor devuelto no se utiliza .
Original:
Because a temporary copy of the object is constructed during the operation, pre-increment or pre-decrement operators are usually more efficient in contexts where the returned value is not used.
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] Biblioteca estándar
Operadores de incremento y decremento están sobrecargados para muchos tipos de bibliotecas estándar. En particular, los operadores
Iterator sobrecargas + + y todos los operadores BidirectionalIterator sobrecargas -, aunque los operadores no-ops para el iterador particular .Original:
Increment and decrement operators are overloaded for many standard library types. In particular, every
Iterator overloads operator++ and every BidirectionalIterator overloads operator--, even if those operators are no-ops for the particular iterator.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Original: overloads for arithmetic types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| aumenta o disminuye el valor atómico por uno Original: increments or decrements the atomic value by one The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::atomic función)
| |
| aumenta o disminuye el contador Original: increments or decrements the tick count The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::chrono::duration función)
| |
Original: overloads for iterator types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| avanza el iterador Original: advances the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::raw_storage_iterator función)
| |
| avanza el iterador Original: advances the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::reverse_iterator función)
| |
| Disminuye el iterador Original: decrements the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::reverse_iterator función)
| |
| no-op (miembro público of std::back_insert_iterator función)
| |
| no-op (miembro público of std::front_insert_iterator función)
| |
| no-op (miembro público of std::insert_iterator función)
| |
| avanza el iterador Original: advances the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::move_iterator función)
| |
| Disminuye el iterador Original: decrements the iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::move_iterator función)
| |
| avanza el istream_iterator Original: advances the istream_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::istream_iterator función)
| |
| no-op (miembro público of std::ostream_iterator función)
| |
| avanza la istreambuf_iterator Original: advances the istreambuf_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::istreambuf_iterator función)
| |
| no-op (miembro público of std::ostreambuf_iterator función)
| |
| avanza la regex_iterator Original: advances the regex_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::regex_iterator función)
| |
| avanza la regex_token_iterator Original: advances the regex_token_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público of std::regex_token_iterator función)
| |
[editar] Ver también
| Common operators | ||||||
|---|---|---|---|---|---|---|
| asignación | incrementNJdecrement | aritmética | lógico | comparación | memberNJaccess | otro |
|
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
| Special operators | ||||||
|
static_cast convierte un tipo a otro tipo
compatible Original: static_cast converts one type to another compatible type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. dynamic_cast convierte clase base virtual a class
derivada Original: dynamic_cast converts virtual base class to derived class The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. const_cast convierte un tipo a otro compatible con diferentes cv qualifiers
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. reinterpret_cast convierte el tipo de type
incompatible Original: reinterpret_cast converts type to incompatible type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. new asigna memory
Original: new allocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. delete desasigna memory
Original: delete deallocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. sizeof consulta el tamaño de un type
Original: sizeof queries the size of a type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. sizeof... consulta el tamaño de un parámetro de paquete (ya que C + +11)
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. typeid consulta la información de una type
Original: typeid queries the type information of a type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. noexcept comprueba si una expresión puede lanzar una excepción (ya que C + +11)
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. alignof consultas requisitos de alineación de un (ya que C + +11) tipo
Original: alignof queries alignment requirements of a type (ya que C + +11) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||