Namensräume
Varianten
Aktionen

Assignment 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
 
Zuweisungsoperatoren ändern Sie den Wert des Objekts .
Original:
Assignment operators modify 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
basic assignment a = b Yes T& T::operator =(const T2& b); N/A
move assignment (C++11) a = rvalue Yes T& T::operator =(T2&& b); N/A
addition assignment a += b Yes T& T::operator +=(const T2& b); T& operator +=(T& a, const T2& b);
subtraction assignment a -= b Yes T& T::operator -=(const T2& b); T& operator -=(T& a, const T2& b);
multiplication assignment a *= b Yes T& T::operator *=(const T2& b); T& operator *=(T& a, const T2& b);
division assignment a /= b Yes T& T::operator /=(const T2& b); T& operator /=(T& a, const T2& b);
modulo assignment a %= b Yes T& T::operator %=(const T2& b); T& operator %=(T& a, const T2& b);
bitwise AND assignment a &= b Yes T& T::operator &=(const T2& b); T& operator &=(T& a, const T2& b);
bitwise OR assignment a |= b Yes T& T::operator |=(const T2& b); T& operator |=(T& a, const T2& b);
bitwise XOR assignment a ^= b Yes T& T::operator ^=(const T2& b); T& operator ^=(T& a, const T2& b);
bitwise left shift assignment a <<= b Yes T& T::operator <<=(const T2& b); T& operator <<=(T& a, const T2& b);
bitwise right shift assignment a >>= b Yes T& T::operator >>=(const T2& b); T& operator >>=(T& a, const T2& b);
'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.
  • Alle integrierten Zuweisungsoperatoren zurückzukehren *this und am meisten benutzerdefinierten Überlastungen auch *this so dass die benutzerdefinierte Operatoren in der gleichen Weise wie die Einbauten verwendet werden kann zurückzukehren. Jedoch in einer benutzerdefinierten Operator Überlast kann jeder Typ als Rückkehr-Typ (einschließlich void) verwendet werden .
    Original:
    All built-in assignment operators return *this, and most user-defined overloads also return *this 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.
  • T2 kann jeder Typ einschließlich T sein
    Original:
    T2 can be any type including T
    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

Zuweisungsoperator Operator ersetzt den Inhalt des Objekts a mit einer Kopie des Inhalts b (b wird nicht modifiziert). Für Klasse-Typen ist dies eine spezielle Elementfunktion, in Kopieren Zuweisungsoperator beschrieben .
Original:
copy assignment operator replaces the contents of the object a with a copy of the contents of b (b is no modified). For class types, this is a special member function, described in Kopieren Zuweisungsoperator.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
' Bewegen Zuordnung Operator ersetzt den Inhalt des Objekts a mit dem Inhalt b unter Vermeidung Kopierens wenn möglich (b kann modifiziert werden). Für Klasse-Typen ist dies eine spezielle Elementfunktion, in bewegen Zuweisungsoperator beschrieben. (seit C++11)
Original:
move assignment operator replaces the contents of the object a with the contents of b, avoiding copying if possible (b may be modified). For class types, this is a special member function, described in bewegen Zuweisungsoperator. (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.
Für Nicht-Klasse-Typen sind Kopieren und Verschieben Zuordnung zu unterscheiden und werden als direkte Zuordnung bezeichnet .
Original:
For non-class types, copy and move assignment are indistinguishable and are referred to as direct assignment.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
' Verbundzuweisung Betreiber ersetzen den Inhalt der Inhalt des Objekts a mit dem Ergebnis einer binären Operation zwischen dem vorherigen Wert des a und dem Wert des b .
Original:
compound assignment operators replace the contents the contents of the object a with the result of a binary operation between the previous value of a and the value of b.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Builtin direkte Zuordnung

Für jede Art T, beteiligen die folgende Funktion Signaturen in Überlast-Auflösung:
Original:
For every type T, 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.
T*& operator=(T*&, T*);
T*volatile & operator=(T*volatile &, T*);
Für jede Aufzählung oder Zeiger auf Elementtyp T, wahlweise flüchtigen qualifizierte, beteiligt sich die folgende Funktion Signatur in Überlast-Auflösung:
Original:
For every enumeration or pointer to member type T, optionally volatile-qualified, the following function signature participates 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.
T& operator=(T&, T );
Für jedes Paar A1 und A2, wobei A1 ist ein arithmetischer Typ (optional flüchtigen qualifizierte) und A2 ist ein befördert arithmetischen Typ, beteiligt sich die folgende Funktion Signatur in Überlast-Auflösung:
Original:
For every pair A1 and A2, where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signature participates 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.
A1& operator=(A1&, A2);
Für Ausdrücke E1 jeder skalaren Typ T, werden die folgenden zusätzlichen Formen der builtin Zuweisungsausdruck erlaubt:
Original:
For expressions E1 of any scalar type T, the following additional forms of the builtin assignment expression are allowed:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
E1 = {}
(seit C++11)
E1 = {E2}
(seit C++11)
Hinweis: Die oben sind alle Nicht-Klasse-Typen außer Referenztypen, Array-Typen, Funktionstypen und der Art void, die nicht direkt zuordenbaren .
Original:
Note: the above includes all non-class types except reference types, array types, function types, and the type void, which are not directly assignable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Die direkte Zuordnung Betreiber rechnet mit einem modifizierbaren lvalue als linken Operanden und gibt eine lvalue Identifizierung des linken Operanden nach der Änderung. Für Nicht-Klasse-Typen, der rechte Operand ersten implizit konvertiert der cv-unqualifizierte Typ des linken Operanden und dann wird sein Wert in das Objekt mit der linken Operanden identifiziert kopiert .
Original:
The direct assignment operator expects a modifiable lvalue as its left operand and returns an lvalue identifying the left operand after modification. For non-class types, the right operand is first implizit konvertiert to the cv-unqualified type of the left operand, and then its value is copied into the object identified by left operand.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Wenn der linke Operand einen Verweistyp ist, gilt die Abtretung Betreiber bezeichnet-to object .
Original:
When the left operand is a reference type, the assignment operator applies to the referred-to object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Wenn die linke und die rechte Operanden identifizieren überlappenden Objekten, ist das Verhalten undefiniert (es sei denn, die Überlappung genau ist und die Art ist das gleiche)
Original:
If the left and the right operands identify overlapping objects, the behavior is undefined (unless the overlap is exact and the type is the same)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Wenn der rechte Operand ist ein verspannt-init-Liste
Original:
If the right operand is a braced-init-list
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • der Ausdruck E1 = {} entspricht E1 = T(), wo T die Art der E1 ist .
    Original:
    the expression E1 = {} is equivalent to E1 = T(), where T is the type of E1.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • der Ausdruck E1 = {E2} entspricht E1 = T(E2), wo T ist die Art der E1, außer dass Verengen impliziten Konvertierungen verboten sind .
    Original:
    the expression E1 = {E2} is equivalent to E1 = T(E2), where T is the type of E1, except that narrowing implicit conversions are prohibited.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Für Klasse-Typen generiert diese Syntax einen Aufruf an die Zuweisungsoperator mit std::initializer_list als Argument, nach den Regeln der list-Initialisierung
Original:
For class types, this syntax generates a call to the assignment operator with std::initializer_list as the argument, following the rules of list-Initialisierung
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 = 0;  // not an assignment
    n = 1;      // direct asignment
    std::cout << n << ' ';
    n = {};     // zero-initialization, then assignment
    std::cout << n << ' ';
    n = 'a';    // integral promotion, then assignment
    std::cout << n << ' ';
    n = {'b'};   // explicit cast, then assignment
    std::cout << n << ' ';
    n = 1.0;    // floating-point conversion, then assignment
    std::cout << n << ' ';
//    n = {1.0}; // compiler error (narrowing conversion)
 
    int& r = n;  // not an assignment
    int* p;
 
    r = 2;       // assignment through reference
    std::cout << n << ' ';
    p = &n;      // direct assignment
    p = nullptr; // null-pointer conversion, then assignment 
}

Output:

1 0 97 98 1 2

[Bearbeiten] Builtin Verbindung Abtretung an

Für jedes Paar A1 und A2, wobei A1 ist ein arithmetischer Typ (optional flüchtigen qualifizierte) und A2 ist ein befördert arithmetischen Typ, beteiligen die folgende Funktion Signaturen in Überlast-Auflösung:
Original:
For every pair A1 and A2, where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic 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.
A1& operator*=(A1&, A2);
A1& operator/=(A1&, A2);
A1& operator+=(A1&, A2);
A1& operator-=(A1&, A2);
Für jedes Paar I1 und I2, wobei I1 ist ein integraler Typ (optional flüchtigen qualifizierte) und I2 ist ein befördert integraler Typ, die folgende Funktion Signaturen in Überladungsauflösung teilnehmen:
Original:
For every pair I1 and I2, where I1 is an integral type (optionally volatile-qualified) and I2 is a promoted integral 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.
I1& operator%=(I1&, I2);
I1& operator<<=(I1&, I2);
I1& operator>>=(I1&, I2);
I1& operator&=(I1&, I2);
I1& operator^=(I1&, I2);
I1& operator|=(I1&, I2);
Für jedes wahlweise cv qualifizierte Objekttyp T, die folgende Funktion Signaturen in Überladungsauflösung teilnehmen:
Original:
For every optionally cv-qualified object type T, 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.
T*& operator+=(T*&, std::ptrdiff_t);
T*& operator-=(T*&, std::ptrdiff_t);
T*volatile & operator+=(T*volatile &, std::ptrdiff_t);
T*volatile & operator-=(T*volatile &, std::ptrdiff_t);
{{{1}}}
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

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