c++智能指针父类转子类
时间: 2023-08-18 14:04:53 浏览: 499
智能指针的父类转子类需要使用std::dynamic_pointer_cast(smartPointer)函数进行转换。在代码中,我们首先创建一个父类的智能指针p1,然后使用std::dynamic_pointer_cast将其转换为子类的智能指针p2。这样就完成了智能指针的父类转子类操作。需要注意的是,向下转换必须使用dynamic_pointer_cast进行转换。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [C++智能指针父类和子类之间的转换](https://blog.csdn.net/weixin_46222091/article/details/104832221)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [C++父类和子类指针的相互赋值和转换](https://blog.csdn.net/m0_51551385/article/details/125171742)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文