【发布时间】:2013-05-29 17:46:28
【问题描述】:
在传统的 C 中你可以这样做:
int i = 48;
char c = (char)i;
//Now c holds the value of 48.
//(Of course if i > 255 then c will not hold the same value as i).
哪些 c++ 转换方法(static_cast、reinterpret_cast)适合完成这项工作?
【问题讨论】:
-
你也可以
char c = i;不用担心哪个演员是哪个演员。当然,如果你这样做了,你就会与那些坚持将编译器警告转化为错误然后在任何发生的地方进行修复的“到处强制转换”的人发生冲突。