Use of 'const' for function parameters

前端 未结 30 3580
借酒劲吻你
借酒劲吻你 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:39

    I say const your value parameters.

    Consider this buggy function:

    bool isZero(int number)
    {
      if (number = 0)  // whoops, should be number == 0
        return true;
      else
        return false;
    }
    

    If the number parameter was const, the compiler would stop and warn us of the bug.

提交回复
热议问题