Is using increment (operator++) on floats bad style?

后端 未结 4 438
孤街浪徒
孤街浪徒 2020-12-08 10:45

Is it considered \"bad style\" to use the increment operator (++) on floats? It compiles just fine but I find it smelly and counter-intuitive.

The question: In what

4条回答
  •  误落风尘
    2020-12-08 11:15

    It's bad style. ++ and -- are intended to set an lvalue to its next or previous value, like the next or previous integer, the next or previous element in an array (for pointers), the next or previous element in a container (iterators), etc.

    Next and previous values are not well-defined for floats. Do f += 1. explicitly.

提交回复
热议问题