C++ cast 小结# Programming - 葵花宝典
f*n
1 楼
最近研究了一下cast, 成果如下,大家看看如何:
const_cast:
It's only used to add or remove qualifiers: const or volatile. Note: static
_cast can add const and can never remove const.
reinterpret_cast:
It never does any check, neither compile time nor runtime. But it requires
the two types have the same storage size in memory.
static_cast VS dynamic_cast:
In the inheritance hierarchy (all public inheritance), upcast will always
work, even without any type of explicit cast. static_cast will work for
downcast too wi
const_cast:
It's only used to add or remove qualifiers: const or volatile. Note: static
_cast can add const and can never remove const.
reinterpret_cast:
It never does any check, neither compile time nor runtime. But it requires
the two types have the same storage size in memory.
static_cast VS dynamic_cast:
In the inheritance hierarchy (all public inheritance), upcast will always
work, even without any type of explicit cast. static_cast will work for
downcast too wi