Passing a modifiable parameter to c++ function

前端 未结 12 1620
余生分开走
余生分开走 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:27

    The difference here is relatively minor.

    A reference cannot be NULL.

    A nullpointer may be passed. Thus you can check if that happens and react accordingly.

    I personally can't think of a real advantage of one of the two possibilities.

提交回复
热议问题