隐式类型转换(隐式强制转换):在编程语言中,编译器或解释器在不需要程序员显式写出转换语句(如 (int)、static_cast<>)的情况下,自动把一个值从一种类型转换为另一种类型的过程。常见于数值运算、赋值、函数参数传递等场景。(不同语言规则不同;在某些语境中也常称 implicit conversion。)
/ɪmˈplɪsɪt kæst/
An implicit cast happens when you assign an int to a double.
当你把一个 int 赋值给 double 时,会发生一次隐式类型转换。
Because the function expects a size_t, passing a negative int may trigger an implicit cast and produce a very large value, leading to a subtle bug.
因为函数期望的是 size_t,传入负的 int 可能触发隐式类型转换并变成一个很大的值,从而造成隐蔽的 bug。
implicit 来自拉丁语 implicitus(“包含在内的、未明说的”),与 implicate 同源;cast 在这里是“投射/转换”的比喻用法,源自古诺尔斯语 kasta(“投掷”)。合起来表示“不明说但自动发生的转换”。