const_cast<T>(expression)
dynamic_cast<T>(expression)
reinterpret_cast<T>(expression)
static_cast<T>(expression)
const_castis typically used to cast away the constness of objects. It is the only C++-style cast that can do this.dynamic_castis primarily used to perform "safe downcasting," i.e., to determine whether an object is of a particular type in an inheritance hierarchy. It is the only cast that cannot be performed using the old-style syntax. It is also the only cast that may have a significant runtime cost.reinterpret_castis intended for low-level casts that yeld implementation-dependent (i.e., unportable) results, e.g., casting a pointer to anint. Such casts should be rare outside low-level code.static_castcan be used to force implicit conversions (e.g., non-constobject toconstobject,inttodouble, etc.). It can also be used to perform the reverse of many such conversions (e.e.,void *pointers to typed pointers, pointer-to-base to pointer-to-derived), though it cannot cast fromconstto non-constobjects. (Onlyconst_castcan do that.)
출처: Effective C++, Third Edition
Tag // C++ casting

댓글을 달아 주세요