Passing a modifiable parameter to c++ function

前端 未结 12 1640
余生分开走
余生分开走 2020-12-06 19:12

Provided, I want to pass a modifiable parameter to a function, what should I choose: to pass it by pointer or to pass it by reference?

  1. bool GetFoo ( Foo& w
12条回答
  •  半阙折子戏
    2020-12-06 19:32

    One advantage to passing by reference is that they cannot be null (unlike pointers), obviating the need to null-check every out parameter.

提交回复
热议问题