您的位置:首页 > 编程语言 > C语言/C++

C++ 从基类到派生类的转换

2015-03-15 16:50 288 查看
Bulk_item bulk;

Item_base *itemP = &bulk; // ok: dynamic type is Bulk_item

Bulk_item *bulkP = itemP; // error: can't convert base to derived

In those cases when we know that the conversion from base to derived is safe, we can use a static_cast to override the compiler. Alternatively, we could request a conversion that
is checked at run time by using a dynamic_cast.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: