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.
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.
相关文章推荐
- C++基类与派生类的转换
- 命名白白c++ 基类和派生类的转换
- C++基类、派生类指针转换
- C++中派生类和基类的转换和访问控制
- C++中基类和派生类之间的转换实例教程
- C++基类与派生类的转换【zz】
- C++派生类与基类的转换规则
- 派生类到基类的转换(c++学习笔记)
- 派生类到基类的转换(c++学习笔记)
- 从零开始学C++之继承(二):继承与构造函数、派生类到基类的转换
- C/C++开发语言系列之7---C++基类与派生类的转换
- 从零开始学C++之继承(二):继承与构造函数、派生类到基类的转换
- C++ 派生类到基类转换的可访问性
- C++基类和派生类之间的转换
- C++中基类对象安全转换为派生类对象的方法
- C++派生类与基类的转换
- 从零开始学C++之继承(二):继承与构造函数、派生类到基类的转换
- c++派生类转换为基类与public、protected、private继承的关系
- C++基类与派生类的转换
- C/C++日常学习总结(第十四篇)C++基类与派生类的转换