摘要: 二、dynamic_castdynamic_cast仅允许把 指针类型或引用类型 转换成 对象,从而获得一个完整的对象。通常的应用场景是,把派生类的指针转换成基类的指针。看以下程序dynamic_cast.cpp: 1 int main(){ 2 CBase b; CBase* pb; 3 CDerived d; CDerived* pd; 4 pb = dynamic_cast<CBase*>(&d); // ok: derived-to-base 5 pd = dynamic_cast<CDerived*>(&b);... 阅读全文
posted @ 2012-09-17 17:34 yaozhaoyz 阅读(367) 评论(0) 推荐(0) 编辑
摘要: C++提供了四个转换运算符:const_cast <new_type> (expression)static_cast <new_type> (expression)reinterpret_cast <new_type> (expression)dynamic_cast <new_type> (expression)The traditional type-casting equivalents to the abover expressions would be:(new_type) expressionnew_type (expression 阅读全文
posted @ 2012-09-12 14:59 yaozhaoyz 阅读(147) 评论(0) 推荐(0) 编辑