Const correctness for value parameters

前端 未结 6 844
野性不改
野性不改 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:34

    I like const correctness for situations like this:
    void foo(const Bar &b) //I know b cannot be changed
    {
    //do something with b
    }

    This lets me use b without fear of modifying it, but I don't have to pay the cost of a copy constructor.

提交回复
热议问题