隐式类型转换比较常见,在混合类型表达式中经常发生.比如在表达式中存在short和int,那么就过会发生整型提升.四种强制类型转换操作符:static_cast、dynamic_cast、const_cast、reinterpret_cast。
传统的类型转换主要有以下两种形式:
double x = 10.3;
int y;
y = int (x); // functional notation
y = (int) x; // c-like cast notation
为了控制c++ class之间的类型转换,C++提出了四种class类型转换机制,分别具有如下的形式:
dynamic_cast (expression)
reinterpret_cast (expression)
static_cast (expression)
const_cast (expression)