<1>static_cast<目標類型>編譯期檢查,父子類關係能夠轉換安全
<2>dynamic_cast<目標類型>運行期檢查,明確基類指針指向子類引用,轉爲子類指針安全ide
<3>reinterpret_cast<目標類型>編譯期和運行期都不檢查,並且永遠能夠轉換成功函數
<4>const_cast<目標類型>把const類型的指針變爲非const類型的指針spa
const int *fun(int, int){}指針
int* ptr = const_cast<int*>(fun(2, 3));ci
<5>類型轉換操做符 operator 目標類型(void)it
class Point3D;編譯
class Point2Dast
{class
public:
Point2D(int x = 0, int y = 0):m_x(x),m_y(y){}
operator Point3D(void);
private:
int m_x, m_y;
};
Point2D::operator Point3D(void)//此函數須要放在Point3D類聲明的後面
{
return Point3D(m_x, m_y, 0);
}
explicit顯示調用限定符