Operatory rzutowaniaCasting Operators
Istnieje kilka operatorów rzutowania specyficznych dla języka C++.There are several casting operators specific to the C++ language. Te operatory są przeznaczone do usuwania niektórych niejednoznaczności i niebezpieczeństwa związanych ze starym stylem rzutowania języka C.These operators are intended to remove some of the ambiguity and danger inherent in old style C language casts. Są to następujące operatory:These operators are:
dynamic_cast Używane do konwersji typów polimorficznych.dynamic_cast Used for conversion of polymorphic types.
static_cast Używane do konwersji typów niepolimorficznych.static_cast Used for conversion of nonpolymorphic types.
const_cast Służy do usuwania
const
atrybutów,volatile
i__unaligned
.const_cast Used to remove theconst
,volatile
, and__unaligned
attributes.reinterpret_cast Używane do prostej interpretacji bitów.reinterpret_cast Used for simple reinterpretation of bits.
safe_cast Używane w języku C++/CLI do tworzenia zweryfikowanych MSIL.safe_cast Used in C++/CLI to produce verifiable MSIL.
Użyj const_cast
i reinterpret_cast
jako ostatni z nich, ponieważ te operatory mają takie same zagrożenia, jak w przypadku starych stylów.Use const_cast
and reinterpret_cast
as a last resort, since these operators present the same dangers as old style casts. Jednak nadal są one niezbędne w celu całkowitego zastąpienia starych stylów.However, they are still necessary in order to completely replace old style casts.