Namespace
Varianti

Increment/decrement operators

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
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.
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche (deprecato)
noexcept specificatore (C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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)
Specifiers
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 specificatori
Durata di stoccaggio specificatori
constexpr specificatore (C++11)
specificatore auto (C++11)
alignas specificatore (C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Tipo alias dichiarazione (C++11)
attributi (C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della 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.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
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.
esplicito (C++11)
statico
Funzioni membro speciali
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.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni (C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
Incremento / decremento incrementi di operatori o decremento del valore dell'oggetto.
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);
'Nota'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Forme prefisso del incorporata riferimenti ritorno operatori e forme suffissa valori restituiti, e tipici sovraccarichi definiti dall'utente seguono il modello in modo che gli operatori definiti dall'utente possono essere utilizzati nello stesso modo come il built-in. Tuttavia, in una definita dall'utente overload dell'operatore, qualsiasi tipo può essere utilizzato come tipo di ritorno (compresi 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.
  • Il parametro int è un parametro fittizio utilizzato per distinguere tra pre-e post-nelle versioni degli operatori. Quando l'operatore definito dall'utente postfix si chiama, il valore passato tale parametro è sempre zero, anche se può essere modificata chiamando il gestore utilizzando la notazione chiamata di funzione, ad esempio 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.

Indice

[modifica] Spiegazione

Pre-incremento e pre-decremento incrementi di operatori o decremento del valore dell'oggetto e restituisce un riferimento al risultato.
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 e post-decremento crea una copia degli oggetti, incrementi o decremento del valore dell'oggetto e restituisce la copia da prima l'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.

[modifica] Built-in operatori in forma prefissa

Per ogni tipo aritmetico facoltativamente volatili qualificato A diverso bool, e per ogni P puntatore facoltativamente volatili qualificato per tipo di oggetto a scelta cv qualificati, le firme delle funzioni seguenti partecipare risoluzione di sovraccarico:
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&)
(deprecato)
P& operator++(P&)
A& operator--(A&)
P& operator--(P&)
L'operando di un built-in di incremento prefisso o operatore di decremento deve essere un lvalue modificabile (non-const di riferimento) di non booleano tipo aritmetico o puntatore a completare tipo di oggetto. Per questi operandi, il ++x espressione è esattamente equivalente a x+=1, e il --x espressione è esattamente equivalente a x-=1, vale a dire, il risultato è l'operando aggiornato, restituito come valore assegnabile, e tutte le regole di calcolo di conversione e le regole definite per l'aritmetica dei puntatori operatori aritmetici applicano.
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 operatori aritmetici apply.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se l'operando dell'operatore pre-incremento è di bool tipo, è impostato su true (deprecato).
Original:
If the operand of the preincrement operator is of type bool, it is set to true (deprecato).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica] Built-in operatori in forma suffissa

Per ogni tipo aritmetico facoltativamente volatili qualificato A diverso bool, e per ogni P puntatore facoltativamente volatili qualificato per tipo di oggetto a scelta cv qualificati, le firme delle funzioni seguenti partecipare risoluzione di sovraccarico:
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)
(deprecato)
P operator++(P&, int)
A operator--(A&, int)
P operator--(P&, int)
L'operando di un built-in di incremento postfix o operatore di decremento deve essere un lvalue modificabile (non-const di riferimento) di non booleano tipo aritmetico o puntatore a completare tipo di oggetto. Il risultato è un prvalue, che è una copia il valore originale dell'operando. Come effetto collaterale, questo operatore modifica il valore del suo argomento, in quanto se arg valutando arg += 1 o arg -= 1, per incremento e decremento, rispettivamente. Tutte le regole di calcolo di conversione e le regole definite per l'aritmetica dei puntatori operatori aritmetici applicare.
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 operatori aritmetici apply.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se l'operando dell'operatore post-incremento è di bool tipo, è impostato su true (deprecato).
Original:
If the operand of the postincrement operator is of type bool, it is set to true (deprecato).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica] Esempio

#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

[modifica] Note

A causa degli effetti collaterali coinvolti, built-in operatori di incremento e decremento deve essere utilizzato con cautela per evitare un comportamento indefinito a causa di violazioni di sequenziamento regole.
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 sequenziamento regole.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Perché una copia temporanea dell'oggetto viene costruito durante l'operazione, pre-incremento o pre-decremento operatori sono di solito più efficienti in contesti in cui il valore restituito non viene utilizzato.
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.

[modifica] Libreria standard

Operatori di incremento e decremento sono sovraccarichi per molti tipi di libreria standard. In particolare, ogni operatore Iterator sovraccarichi + + e tutti gli operatori BidirectionalIterator sovraccarichi -, anche se tali operatori sono no-ops per l'iteratore particolare.
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.
sovraccarichi per i tipi aritmetici
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.
incrementa o decrementa il valore atomico di 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.

(membro pubblico of std::atomic funzione) [edit]
incrementa o decrementa il conteggio
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.

(membro pubblico of std::chrono::duration funzione)
sovraccarichi per i tipi di iteratori
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 l'iteratore
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.

(membro pubblico of std::raw_storage_iterator funzione)
avanza l'iteratore
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.

(membro pubblico of std::reverse_iterator funzione)
decrementa l'iteratore
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.

(membro pubblico of std::reverse_iterator funzione)
no-op
(membro pubblico of std::back_insert_iterator funzione)
no-op
(membro pubblico of std::front_insert_iterator funzione)
no-op
(membro pubblico of std::insert_iterator funzione)
avanza l'iteratore
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.

(membro pubblico of std::move_iterator funzione)
decrementa l'iteratore
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.

(membro pubblico of std::move_iterator funzione)
fa avanzare il 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.

(membro pubblico of std::istream_iterator funzione)
no-op
(membro pubblico of std::ostream_iterator funzione)
fa avanzare il 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.

(membro pubblico of std::istreambuf_iterator funzione)
no-op
(membro pubblico of std::ostreambuf_iterator funzione)
fa avanzare il 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.

(membro pubblico of std::regex_iterator funzione)
fa avanzare il 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.

(membro pubblico of std::regex_token_iterator funzione)

[modifica] Vedi anche

Precedenza degli operatori

Common operators
assegnazione incrementNJdecrement aritmetica logico confronto memberNJaccess altra

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 converte un tipo a un altro
tipo compatibile
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 converte classe virtuale di base per class
derivato
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 converte il tipo di tipo compatibile con diversi 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 converte tipo type
incompatibile
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 alloca 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 dealloca 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 interroga la dimensione di 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... interroga le dimensioni di un parametro confezione (dal C++11)
Original:
sizeof... queries the size of a parametro confezione (dal 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 interroga le informazioni sul tipo di 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 controlla se un'espressione può lanciare una (dal C++11)
un'eccezione
Original:
noexcept checks if an expression can throw an exception (dal 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 query requisiti di allineamento di un (dal C++11) tipo
Original:
alignof queries alignment requirements of a type (dal C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.