When to use const and const reference in function args?

后端 未结 4 1246
无人共我
无人共我 2020-11-28 23:46

When writing a C++ function which has args that are being passed to it, from my understanding const should always be used if you can guarantuee that the object will not be c

4条回答
  •  粉色の甜心
    2020-11-29 00:05

    The main advantage of const reference over const pointer is following: its clear that the parameter is required and cannot be NULL. Vice versa, if i see a const pointer, i immedeately assume the reason for it not being a reference is that the parameter could be NULL.

提交回复
热议问题