Const correctness for value parameters

前端 未结 6 853
野性不改
野性不改 2020-11-28 12:09

I know there are few question about const correctness where it is stated that the declaration of a function and its definition do not need to agree for value parameters. Thi

6条回答
  •  清酒与你
    2020-11-28 12:20

    My take on it:

    It's not a bad idea, but the issue is minor and your energy might be better spent on other things.

    In your question you provided a good example of when it might catch an error, but occasionally you also end up doing something like this:

    void foo(const int count ...)
    {
       int temp = count;  // can't modify count, so we need a copy of it
       ++temp;
    
       /* ... */
    }
    

    The pros and cons are minor either way.

提交回复
热议问题