C++ self-learning notes(6)
2017-06-22 00:00
459 查看
摘要: Type conversion: static_cast and reinterpret_cast
static_cast and reinterpret_cast are conversion types :
static_cast can perform conversions betwenn pointers and related classes. The command goes as: static_cast<new_type>(expression) . An example is shown below:
![](https://static.oschina.net/uploads/space/2017/0622/205815_BU7Q_2968040.png)
result:
![](https://static.oschina.net/uploads/space/2017/0622/205912_yq57_2968040.png)
reinterpret_cast can convert between completely unrelated pointer types. See the example below:
![](https://static.oschina.net/uploads/space/2017/0622/212647_r8xR_2968040.png)
result:
![](https://static.oschina.net/uploads/space/2017/0622/212736_ni25_2968040.png)
Check more information about type conversion from the link below.
Useful links:
http://blog.csdn.net/jofranks/article/details/7828331 http://www.cnblogs.com/ider/archive/2011/07/31/cpp_cast_operator_part4.html http://www.cnblogs.com/ider/archive/2011/07/30/cpp_cast_operator_part3.html http://blog.csdn.net/zhuichao001/article/details/7924148 http://blog.csdn.net/querw/article/details/7387594 http://blog.csdn.net/jofranks/article/details/7828339 http://www.cplusplus.com/doc/tutorial/typecasting/
to be continued...
static_cast and reinterpret_cast are conversion types :
static_cast can perform conversions betwenn pointers and related classes. The command goes as: static_cast<new_type>(expression) . An example is shown below:
![](https://static.oschina.net/uploads/space/2017/0622/205815_BU7Q_2968040.png)
result:
![](https://static.oschina.net/uploads/space/2017/0622/205912_yq57_2968040.png)
reinterpret_cast can convert between completely unrelated pointer types. See the example below:
![](https://static.oschina.net/uploads/space/2017/0622/212647_r8xR_2968040.png)
result:
![](https://static.oschina.net/uploads/space/2017/0622/212736_ni25_2968040.png)
Check more information about type conversion from the link below.
Useful links:
http://blog.csdn.net/jofranks/article/details/7828331 http://www.cnblogs.com/ider/archive/2011/07/31/cpp_cast_operator_part4.html http://www.cnblogs.com/ider/archive/2011/07/30/cpp_cast_operator_part3.html http://blog.csdn.net/zhuichao001/article/details/7924148 http://blog.csdn.net/querw/article/details/7387594 http://blog.csdn.net/jofranks/article/details/7828339 http://www.cplusplus.com/doc/tutorial/typecasting/
to be continued...
相关文章推荐
- C++ self-learning notes(5)
- C++ self-learning notes(9)
- C++ self-learning notes(3)
- C++ self-learning notes(7)
- C++ self-learning notes(4)
- C++ self-learning notes (1)
- C++ self-learning notes(2)
- C++ self-learning notes(8)
- LeetCode 238. Product of Array Except Self 题解(C++)
- leetcode_c++:Divide and Conquer:Count of Smaller Numbers After Self(315)
- Self Summary: C++函数返回引用和指针的问题,局部对象与new对象的问题
- Self Summary: C++函数返回引用和指针的问题,局部对象与new对象的问题
- C++ self Q/A
- C++中的this和Python的self对比
- 场景中self其实就相当于Java,C++中的this对象
- leetcode 238 Product of Array Except Self C++
- Self Print in C++
- Self Summary: C++函数返回引用和指针的问题,局部对象与new对象的问题
- Can a C++ class have an object of self type?
- C++的this,Objective-C的self