Casting Operators
There are several casting operators specific to the C++ language. These operators are intended to remove some of the ambiguity and danger inherent in old style C language casts. These operators are:
dynamic_cast Used for conversion of polymorphic types.
static_cast Used for conversion of nonpolymorphic types.
const_cast Used to remove the
const
,volatile
, and__unaligned
attributes.reinterpret_cast Used for simple reinterpretation of bits.
safe_cast Used in C++/CLI to produce verifiable MSIL.
Use const_cast
and reinterpret_cast
as a last resort, since these operators present the same dangers as old style casts. However, they are still necessary in order to completely replace old style casts.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: Under hela 2024 kommer vi att fasa ut GitHub-problem som feedbackmekanism för innehåll och ersätta det med ett nytt feedbacksystem. Mer information finns i:Skicka och visa feedback för