相关疑难解决方法(0)

什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast?

有什么用途:

  • static_cast
  • dynamic_cast
  • const_cast
  • reinterpret_cast
  • C风格演员 (type)value
  • 功能式演员 type(value)

如何决定在哪些特定情况下使用哪个?

c++ pointers casting c++-faq

2367
推荐指数
9
解决办法
52万
查看次数

C++演员语法样式

Regular cast vs. static_cast vs. dynamic_cast相关的问题:

你更喜欢C++中的演员语法风格?

  • C风格的演员语法: (int)foo
  • C++ - 样式转换语法: static_cast<int>(foo)
  • 构造函数语法: int(foo)

它们可能无法转换为完全相同的指令(是吗?)但它们的效果应该相同(对吗?).

如果你只是在内置数值类型之间进行转换,我发现C++风格的转换语法太冗长了.作为以前的Java编码器,我倾向于使用C风格的转换语法,但我的本地C++专家坚持使用构造函数语法.

你怎么看?

c++ casting coding-style

30
推荐指数
3
解决办法
1万
查看次数

标签 统计

c++ ×2

casting ×2

c++-faq ×1

coding-style ×1

pointers ×1