Use of 'const' for function parameters

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

    To summarize:

    • "Normally const pass-by-value is unuseful and misleading at best." From GOTW006
    • But you can add them in the .cpp as you would do with variables.
    • Note that the standard library doesn't use const. E.g. std::vector::at(size_type pos). What's good enough for the standard library is good for me.

提交回复
热议问题