c++ - int(floatvar) 和 (int)floatvar 之间有区别吗?

标签 c++ language-features typecast-operator

<分区>

Possible Duplicate:
C++: What's the difference between function(myVar) and (function)myVar ?

我已经看到并使用了这些类型转换的两种变体:

int(floatvar)

(int)floatvar

这两者有什么区别吗?关于何时使用哪个有任何偏好吗?

最佳答案

它们之间没有区别。 (int)floatvar是 C 的转换方式,其中 as int(floatvar)是 C++ 方式(尽管最好是显式使用 static_cast<> )。

关于c++ - int(floatvar) 和 (int)floatvar 之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4497908/

相关文章:

c++ - 关于ipp镜像构建

Java 语言规范 - 无法理解 'BlockStatement'

c++ - 与 lambda 成对 vector 的 lower_bound

c++ - std::make_shared() 是否使用自定义分配器?

c++ - C/C++ 中结构的 `new` 和 `new()` 有什么区别?

c++ - 自定义类型、类型转换导致运算符冲突?

c++ - "invalid cast from type ' const myClass ' to type ' int '",我怎样才能让它有效?

c++ - 尽管定义了强制转换运算符,但没有强制转换

c++ - 模板赋值运算符不会替换默认的赋值运算符

c# - 为什么我不能在 C# 中执行 ??=?