On Thu, 27 Jan 2022 at 04:03, Victor Eijkhout via SG20 <sg20@lists.isocpp.org> wrote:

On , 2022Jan26, at 13:33, Arthur O'Dwyer <arthur.j.odwyer@gmail.com> wrote:

FWIW, I teach
- pass-by-value
- problems: performance of all those copies; how to write an out-parameter?
- C solution: pointers (a pointer holds a memory address)
- pass-by-pointer
- C++ enhancement: references (***)
- pass-by-reference

I agree with your sequence, and I use something very similar.


Why do you teach the “pass by pointer”?

My 2 cents here (in addition to Arthur’s good reply). I think there is a use in daily programming to describe ‘potentially null’. Some people prefer std::optional, but it has a bad performance impact, especially on large objects, and it can only be used on an ‘in’ parameter, but not an ‘out’ or ‘in-out’ parameter. If there is no ownership involved and the argument can be ‘missing’, I would recommend using a pointer (as versus a reference that is not allowed to be null).

Yongwei Wu
URL: http://wyw.dcweb.cn/