Namensräume
Varianten
Aktionen

Increment/decrement operators

Aus cppreference.com
< cpp‎ | language

 
 
Sprache C++
Allgemeine Themen
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.
Flusskontrolle
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.
Bedingte Ausführung Aussagen
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.
Iterationsanweisungen
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.
Gehe Aussagen
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.
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktion Erklärung
Lambda-Funktion Erklärung
Funktions-Template
inline-Spezifizierer
Exception-Spezifikationen (veraltet)
noexcept Spezifizierer (C++11)
Ausnahmen
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
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 Planer
Lagerdauer Planer
constexpr Spezifizierer (C++11)
auto Spezifizierer (C++11)
alignas Spezifizierer (C++11)
Initialisierung
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literale
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alternative Darstellungen
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.
Types
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
Typ Aliasdeklaration (C++11)
Attribute (C++11)
Wirft
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
impliziten Konvertierungen
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-Stil und funktionale Besetzung
Speicherzuweisung
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.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Class-spezifische Funktion Eigenschaften
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.
explizit (C++11)
statisch
Besondere Member-Funktionen
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.
Templates
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Klassen-Template
Funktions-Template
Template-Spezialisierung
Parameter Packs (C++11)
Verschiedenes
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Inline Montage
 
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.
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);
'Notes'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Formen der Präfix der eingebauten Operatoren Rückkehr Referenzen und Postfix Formen Rückgabewerte und typischen benutzerdefinierten Überlastungen dem Muster folgen, so dass die benutzerdefinierten Operatoren in der gleichen Weise wie die Einbauten verwendet werden kann. Jedoch in einer benutzerdefinierten Operator Überlast kann jeder Typ als Rückkehr-Typ (einschließlich void) verwendet werden .
    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.
  • Die int Parameter eine Dummy-Parameter verwendet, um zwischen Prä-und Post-in-Versionen der Betreiber differenzieren. Wenn der Benutzer-definierten Postfix-Operator genannt wird, ist der Wert in diesem Parameter übergeben immer Null, obwohl es durch den Aufruf der Betreiber mit der Funktion Anruf Schreibweise geändert werden können, z. B. 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.

Inhaltsverzeichnis

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

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

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

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

[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.
Überladungen für arithmetische Typen
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) [edit]
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)
Überladungen für Iterator-Typen
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

Operator Vorrang

Common operators
Zuweisungen incrementNJdecrement Arithmetik logisch Vergleich memberNJaccess andererseits

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 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:
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 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:
sizeof... queries the size of a Parameter Pack (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.
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:
noexcept checks if an expression can throw an exception (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.
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.