Why do you need to append an L or F after a value assigned to a C++ constant?

前端 未结 4 2108
情深已故
情深已故 2020-12-05 14:54

I have looked at quite a few places online and can\'t seem to find a good explanation as to why we should append an F or L after a value assigned to a C++ constant.

4条回答
  •  感动是毒
    2020-12-05 15:38

    Your example does not need it, but the biggest reason I know of to use explicit types on literal values is to make sure that the correct function overload is called.

    This can make a large difference in constructors, operator overloads, etc.

    Sometimes there is no convenient way to get the literal into the right type, so you have to use a static_cast or put a constructor around the literal.

提交回复
热议问题