3 ms·
>If either of these conditions do not hold then you don't need the distinction. Agreed, but both conditions do hold. C++, C# and Swift support both call-by-val
by fauigerzigerk 9y ago
>If either of these conditions do not hold then you don't need the distinction.
Agreed, but both conditions do hold. C++, C# and Swift support both call-by-value and call-by-reference. And the feature is actually used as most of these languages don't have (or didn't originally have) tuples or multi-valued return.
Whether or not it's a good idea to assign to reference parameters is a wholly different matter. But even bad ideas need language to explain them.
- UncleMeat 9y agoBut cpp doesn't have call-by-reference. It has the ability to refer to pointer and reference objects directly and pass those by value. foo(int* x) takes a pointer by value. foo(int& x) takes a reference by value.
- fauigerzigerk 9y agoThat's nitpicking. Pass-by-reference is defined by its semantics, not by an implementation that avoids copying anything. There is no such thing as a "reference object" in C++ that you could pass by value. References may be implemented using pointers under the hood and those pointers may be copied, but on a semantic level references themselves are not objects that you can copy or take the address of (contrary to pointers).