mirror of
https://github.com/huihut/interview.git
synced 2025-12-18 13:04:38 +03:00
@@ -1102,7 +1102,7 @@ unique_ptr 是 C++11 才开始提供的类型,是一种在异常时可以帮
|
||||
|
||||
| 转换类型 | 安全性 | 示例 |
|
||||
|--------------------------|--------------|--------------------------|
|
||||
| 数值类型转 | ✅ 安全 | `float f=3.14; int i=static_cast<int>(f);` |
|
||||
| 数值类型转换 | ✅ 安全 | `float f=3.14; int i=static_cast<int>(f);` |
|
||||
| 类向上转换 | ✅ 安全 | `Derived* d; Base* b=static_cast<Base*>(d);` |
|
||||
| 类向下转换 | ⚠️ 不安全 | `Base* b=new Base; Derived* d=static_cast<Derived*>(b);` |
|
||||
| 类不变转换 | ✅ 安全 | `MyClass* p; MyClass* same=static_cast<MyClass*>(p);` |
|
||||
|
||||
Reference in New Issue
Block a user