Espacios de nombres
Variantes
Acciones

Increment/decrement operators

De cppreference.com
< cpp‎ | language

 
 
Lenguaje C++
Los temas generales
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.
Control de flujo
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.
Sentencias condicionales ejecución
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.
Instrucciones de iteración
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 declaraciones
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.
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaración de la función
lambda declaración de la función
función de plantilla
especificador inline
especificaciones de excepción (obsoleto)
noexcept especificador (C++11)
Excepciones
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los espacios de nombres
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)
Los 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
almacenamiento duración especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialización
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los literales
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expresiones
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representaciones alternativas
Utilidades
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
alias de tipo de declaración (C++11)
atributos (C++11)
Lanza
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversiones implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-cast estilo y funcional
De asignación de memoria
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.
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clase propiedades específicas de la función
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.
Funciones especiales miembro
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.
Plantillas
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clase de plantilla
función de plantilla
plantilla de especialización
paquetes de parámetros (C++11)
Varios
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaje en línea
 
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.
Operator name Syntax Over​load​able 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);
'Notas'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Formas de prefijo de la incorporada en las referencias operadores y formas de devolución de sufijo valores de retorno y típicas sobrecargas definidas por el usuario siguen el patrón de manera que los operadores definidos por el usuario se pueden utilizar de la misma manera como la empotrados. Sin embargo, en una definida por el usuario sobrecarga del operador, cualquier tipo puede ser utilizado como tipo de retorno (incluyendo void) .
    Original:
    Prefix forms of the built-in operators return references and postfix forms return values, and typical user-defined overloads follow the pattern so that the user-defined operators can be used in the same manner as the built-ins. However, in a user-defined operator overload, any type can be used as return type (including void).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • El parámetro int es un parámetro ficticio utilizado para diferenciar entre pre-y post-en versiones de los operadores. Cuando el definido por el usuario operador de sufijo se llama, el valor que se pasa en el parámetro es siempre cero, aunque puede ser cambiado mediante una llamada al operador usando la notación de función de llamada, por ejemplo, a.operator++(2) .
    Original:
    The int parameter is a dummy parameter used to differentiate between pre- and post- in versions of the operators. When the user-defined postfix operator is called, the value passed in that parameter is always zero, although it may be changed by calling the operator using function call notation, e.g. a.operator++(2).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Contenido

[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.
' 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.

[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.
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.
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.

[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.
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.
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.

[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.
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.

[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.
sobrecargas para tipos aritméticos
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) [edit]
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)
sobrecargas para tipos de iterador
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

La precedencia de operadores

Common operators
asignación incrementNJdecrement aritmética lógico comparación memberNJaccess otro

a = b
a = rvalue
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b

a[b]
*a
&a
a->b
a.b
a->*b
a.*b

a(...)
a, b
(type) 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:
const_cast converts type to compatible type with different cv qualifiers
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 (desde C++11)
Original:
sizeof... queries the size of a parámetro de paquete (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.
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 (desde C++11)
Original:
noexcept checks if an expression can throw an exception (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.
alignof consultas requisitos de alineación de un (desde C++11) tipo
Original:
alignof queries alignment requirements of a 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.