C++ function parameters: use a reference or a pointer (and then dereference)?

后端 未结 11 2211
臣服心动
臣服心动 2021-02-05 10:49

I was given some code in which some of the parameters are pointers, and then the pointers are dereferenced to provide values. I was concerned that the pointer dereferencing wou

11条回答
  •  鱼传尺愫
    2021-02-05 11:12

    My rule of thumb is to pass by pointer if the parameter can be NULL, ie optional in the cases above, and reference if the parameter should never be NULL.

提交回复
热议问题