Increment/decrement operators
Aus 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. |
Increment / Dekrement-Operatoren erhöht oder vermindert den Wert des Objekts .
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); |
|
[Bearbeiten] Erklärung
Pre-increment und Prä-Dekrement Betreiber erhöht oder vermindert den Wert des Objektes und gibt einen Verweis auf das Ergebnis .
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-Inkrement und Post-Dekrement erstellt eine Kopie des Objekts, erhöht oder vermindert den Wert des Objektes und gibt die Kopie aus der Zeit vor dem Inkrement oder Dekrement .
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.
[Bearbeiten] Built-in Präfix-Operatoren
Für jedes wahlweise flüchtigen qualifizierte arithmetischen Typ
A
andere als bool, und für jeden wahlweise flüchtigen qualifizierte Zeiger P
optional cv qualifizierte Objekttyp, die folgende Funktion Signaturen in Überladungsauflösung teilnehmen: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&) |
(veraltet) | |
P& operator++(P&) |
||
A& operator--(A&) |
||
P& operator--(P&) |
||
Der Operand eines eingebauten Präfix-Inkrement-oder Dekrement-Operator muss eine modifizierbare lvalue (non-const-Referenz) von nicht-boolean arithmetischen Typ oder Zeiger auf Objekt-Typ zu vervollständigen. Aus diesen Operanden, der Ausdruck ++x entspricht genau x+=1 ist, und der Ausdruck --x entspricht genau x-=1, das heißt, ist das Ergebnis der aktualisierte Operanden, wie L-Wert zurückgegeben und alle arithmetischen Umrechnungsregeln und Zeigerarithmetik Regeln definiert für arithmetischen Operatoren gelten .
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 arithmetischen Operatoren 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.
Wenn der Operand des Prä-Inkrement-Operator ist vom Typ bool, wird es auf true (veraltet) .
Original:
If the operand of the preincrement operator is of type bool, it is set to true (veraltet).
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.
[Bearbeiten] Built-in Postfix-Operatoren
Für jedes wahlweise flüchtigen qualifizierte arithmetischen Typ
A
andere als bool, und für jeden wahlweise flüchtigen qualifizierte Zeiger P
optional cv qualifizierte Objekttyp, die folgende Funktion Signaturen in Überladungsauflösung teilnehmen: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) |
(veraltet) | |
P operator++(P&, int) |
||
A operator--(A&, int) |
||
P operator--(P&, int) |
||
Der Operand eines eingebauten postfix Inkrement oder Dekrement-Operator muss eine modifizierbare lvalue (non-const-Referenz) von nicht-boolean arithmetischen Typ oder Zeiger auf Objekt-Typ zu vervollständigen. Das Ergebnis ist ein prvalue, die eine Kopie der ursprüngliche Wert des Operanden. Als Nebeneffekt, ändert dieser Operator den Wert des Arguments
arg
, als ob durch die Auswertung arg += 1 oder arg -= 1 für Inkrement-und Dekrement sind. Alle arithmetischen Umrechnungsregeln und Zeigerarithmetik Regeln für arithmetischen Operatoren gelten definiert .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 arithmetischen Operatoren 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.
Wenn der Operand des Postinkrement Betreiber ist vom Typ bool, wird es auf true (veraltet) .
Original:
If the operand of the postincrement operator is of type bool, it is set to true (veraltet).
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.
[Bearbeiten] Beispiel
#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
[Bearbeiten] Notes
Wegen der Nebenwirkungen beteiligt sind, müssen eingebaute Inkrement-und Dekrement-Operatoren mit Vorsicht verwendet werden, um undefiniertes Verhalten aufgrund von Verstößen gegen Sequenzierung Regeln vermeiden .
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 Sequenzierung Regeln.
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.
Da eine temporäre Kopie des Objekts während des Betriebs ausgebildet ist, Prä-Inkrement' oder' Prä-Dekrement Operatoren sind in der Regel effizienter in Kontexten, wo der zurückgegebene Wert nicht verwendet wird .
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.
[Bearbeiten] Standard-Bibliothek
Inkrement-und Dekrement-Operatoren sind für viele Standard-Bibliothek Typen überlastet. Insbesondere jeden
Iterator
Überlastungen operator + + und jede BidirectionalIterator
Überlastungen Betreiber -, auch wenn diese Betreiber keine-ops für die jeweilige Iterator sind .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. | |
erhöht oder vermindert den atomaren Wert um eins 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. (öffentliche Elementfunktion of std::atomic )
| |
erhöht oder verringert die Anzahl der Ticks 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. (öffentliche Elementfunktion of std::chrono::duration )
| |
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. | |
Fortschritte der Iterator 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. (öffentliche Elementfunktion of std::raw_storage_iterator )
| |
Fortschritte der Iterator 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. (öffentliche Elementfunktion of std::reverse_iterator )
| |
Verringert den Iterator 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. (öffentliche Elementfunktion of std::reverse_iterator )
| |
no-op (öffentliche Elementfunktion of std::back_insert_iterator )
| |
no-op (öffentliche Elementfunktion of std::front_insert_iterator )
| |
no-op (öffentliche Elementfunktion of std::insert_iterator )
| |
Fortschritte der Iterator 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. (öffentliche Elementfunktion of std::move_iterator )
| |
Verringert den Iterator 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. (öffentliche Elementfunktion of std::move_iterator )
| |
Fortschritte der 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. (öffentliche Elementfunktion of std::istream_iterator )
| |
no-op (öffentliche Elementfunktion of std::ostream_iterator )
| |
Fortschritte der 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. (öffentliche Elementfunktion of std::istreambuf_iterator )
| |
no-op (öffentliche Elementfunktion of std::ostreambuf_iterator )
| |
Fortschritte der 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. (öffentliche Elementfunktion of std::regex_iterator )
| |
Fortschritte der 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. (öffentliche Elementfunktion of std::regex_token_iterator )
|
[Bearbeiten] Siehe auch
Common operators | ||||||
---|---|---|---|---|---|---|
Zuweisungen | incrementNJdecrement | Arithmetik | logisch | Vergleich | memberNJaccess | andererseits |
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
Special operators | ||||||
static_cast wandelt einem Typ in einen anderen kompatiblen Typ
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 wandelt virtuellen Basisklasse abgeleitet class
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 wandelt Typ kompatiblen Typ mit unterschiedlichen 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 wandelt Typ inkompatibel type
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 ordnet 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 freigibt 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 fragt die Größe eines 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... fragt die Größe eines Parameter Pack (seit 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 fragt die Typinformationen eines 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 prüft, ob ein Ausdruck eine Ausnahme (seit C++11)
werfen kann Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. alignof Abfragen Ausrichtungsanforderungen eines Typs (seit C++11)
Original: alignof queries alignment requirements of a type (seit C++11) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |