Namensräume
Varianten

const_cast conversion

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.
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
 
Konvertiert zwischen Typen mit unterschiedlichen cv-Qualifikation .
Original:
Converts between types with different cv-qualification.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten]Syntax

const_cast <new_type> (expression)
Gibt einen Wert vom Typ new_type .
Original:
Returns a value of type new_type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]Erklärung

Nur die folgenden Konvertierungen können mit const_cast durchgeführt werden. Insbesondere darf nur const_cast verwendet zu werfen (entfernen) Konstantheit oder Volatilität werden .
Original:
Only the following conversions can be done with const_cast. In particular, only const_cast may be used to cast away (remove) constness or volatility.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
Zwei möglicherweise mehrstufige Zeiger auf die gleiche Art können untereinander konvertiert werden, unabhängig von cv-Qualifikation auf jeder Ebene .
Original:
Two possibly multilevel pointers to the same type may be converted between each other, regardless of cv-qualifiers at each level.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
Lvalue aller Art T kann zu einem L-Wert oder rvalue Verweis auf die gleiche Art T, mehr oder weniger qualifizierte cv umgewandelt werden. Ebenso kann eine rvalue zu einer mehr oder weniger cv qualifizierte rvalue Verweis umgewandelt werden .
Original:
lvalue of any type T may be converted to a lvalue or rvalue reference to the same type T, more or less cv-qualified. Likewise, an rvalue may be converted to a more or less cv-qualified rvalue reference.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
Es gelten dieselben Regeln, um möglicherweise mehrstufige Zeiger auf Daten Mitgliedern .
Original:
Same rules apply to possibly multilevel pointers to data members.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
Null-Zeiger-Wert kann auf den Null-Zeiger-Wert von new_type umgewandelt werden
Original:
null pointer value may be converted to the null pointer value of new_type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Wie bei allen Besetzung Ausdrücke, ist das Ergebnis:
Original:
As with all cast expressions, the result is:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • ein L-Wert, wenn new_type ist ein L-Wert Referenz-Typ oder ein rvalue Bezug auf Art funktionieren;
    Original:
    an lvalue if new_type is an lvalue reference type or an rvalue reference to function type;
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • ein xWert wenn new_type ist ein rvalue Verweis auf Objekttyp;
    Original:
    an xvalue if new_type is an rvalue reference to object type;
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • a prvalue sonst .
    Original:
    a prvalue otherwise.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]Notes

Zeiger auf Funktionen und Zeiger auf Member-Funktionen unterliegen nicht const_cast
Original:
Pointers to functions and pointers to member functions are not subject to const_cast
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Obwohl const_cast kann Konstantheit von jedem Zeiger oder eine Referenz zu entfernen, mit der daraus resultierenden Zeiger oder eine Referenz auf ein Objekt, das erklärt const aufruft undefined Verhalten wurde schreiben .
Original:
Even though const_cast may remove constness from any pointer or reference, using the resulting pointer or reference to write to an object that was declared const invokes undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten]Keywords

const_cast

[Bearbeiten]Beispiel

#include <iostream>   struct type { type():i(3){}void m1(int v)const{// this->i = v; // compile error: this is a pointer to constconst_cast<type*>(this)->i = v;// OK}int i;};   int main(){int i =3;// i is not declared constconstint& cref_i = i;const_cast<int&>(cref_i)=4;// OK: modifies istd::cout<<"i = "<< i <<'\n';   type t; t.m1(4);std::cout<<"type::i = "<< t.i<<'\n';   constint j =3;// j is declared constint* pj =const_cast<int*>(&j);*pj =4;// undefined behavior!   void(type::*mfp)(int)const=&type::m1;// pointer to member function// const_cast<void(type::*)(int)>(mfp); // compiler error: const_cast does not// work on function pointers}

Output:

i = 4 type::i = 4

[Bearbeiten]Siehe auch

close