Use of 'const' for function parameters

前端 未结 30 2819
借酒劲吻你
借酒劲吻你 2020-11-22 03:06

How far do you go with const? Do you just make functions const when necessary or do you go the whole hog and use it everywhere? For example, imag

30条回答
  •  别跟我提以往
    2020-11-22 03:30

    All the consts in your examples have no purpose. C++ is pass-by-value by default, so the function gets copies of those ints and booleans. Even if the function does modify them, the caller's copy is not affected.

    So I'd avoid extra consts because

    • They're redudant
    • They clutter up the text
    • They prevent me from changing the passed in value in cases where it might be useful or efficient.

提交回复
热议问题