reinterpret_cast和C风格的cast有什么区别? [英] What is the difference between a reinterpret_cast and a C-style cast?
本文介绍了reinterpret_cast和C风格的cast有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下两者之间的区别:
double x = 10.3;
int y;
y = (int) x; // c-like cast notation
和:
double x = 10.3;
int y;
y = reinterpret_cast<int>(x)
推荐答案
C风格的Cast可以是以下任何类型的Cast:
A C-style cast can be any of the following types of casts:
-
const_cast
-
static_cast
-
static_cast
后跟一个const_cast
-
reinterpret_cast
-
reinterpret_cast
后接const_cast
const_cast
static_cast
static_cast
followed by aconst_cast
reinterpret_cast
reinterpret_cast
followed by aconst_cast
从列表中可以做的第一个是C风格的转换将执行什么(从C ++ 03 5.4:显式类型转换(cast符号)
the first one from that list that can be done is the what the C-style cast will perform (from C++03 5.4: "Explicit type conversion (cast notation)"
所以你的例子:
double x = 10.3;
int y;
y = (int) x;
code> static_cast 。
the type of cast used would be a static_cast
.
和 y = reinterpret_cast< int>(x);
将无法编译。
这篇关于reinterpret_cast和C风格的cast有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文