static_cast 类型转换无效
时间: 2023-11-12 10:06:56 浏览: 381
cpp代码-c++类型转换 (cast)
静态转换(static_cast)在某些情况下可能无效。它不能将一个不相关的指针类型转换为另一个不相关的指针类型,也不能将指针转换为`int`类型。此外,它也不能像`const_cast`一样将常量转换为非常量类型。静态转换的主要应用是在用户定义了相关的构造函数或转换例程时进行类型转换,以及在继承体系中进行向下转型。请注意,静态转换只适用于指针或引用,不能应用于对象本身。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [记一次c++类型转换导致的崩溃](https://blog.csdn.net/weixin_42288955/article/details/127793192)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [C++类型转换----static_cast](https://blog.csdn.net/u010154685/article/details/51799954)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文