C++ Logo

sg20

Advanced search

Re: Introducing references

From: Victor Eijkhout <eijkhout_at_[hidden]>
Date: Wed, 26 Jan 2022 20:03:27 +0000


On , 2022Jan26, at 13:33, Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]<mailto:arthur.j.odwyer_at_[hidden]>> 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.

But…..

Why do you teach the “pass by pointer”? Maybe you and I have different audiences. I have 1 semester to get engineering undergrads writing (from scratch) semi-serious simulations in clear, working, not-too-inefficient code. So I teach the C stuff way at the end of the semester as “In case someone throws you an old code base, you may come across this.” Otherwise I see no reason for teaching it.

Otherwise thanks for agreeing (or at least sympathizing) with me.

Victor.

Received on 2022-01-26 20:03:33