如何在此语句中使用static_cast

How to use static_cast in this statement

本文关键字:static cast 语句      更新时间:2023-10-16

我有这样的语句: amount *= factor;

amount定义为整数,其中 factor 定义为双精度。因此,将amountfactor相乘的结果将是 double 型。我想使用 static_cast 来确保生成的 amount 变量转换为 int .

在这种情况下,我会怎么做?

这里不需要投射,它会自动转换为!!