Liste des Groupes | Revenir à cl c |
David Brown <david.brown@hesbynett.no> writes:That seems a subtle distinction - I'll have to think about it a little. I like your description of arguments being like local variable initialisation - it makes sense equally well regardless of whether the parameter is "int", "int*", or "int&". (It's probably best not to mention the other one in this group...)
On 16/08/2024 02:08, Ben Bacarisse wrote:Bart <bc@freeuk.com> writes:The best way to think about C++ (in my very non-expert opinion) is to>In general there is no reason, in a language with true call-by-reference,I can't unravel this. Take, as a concrete example, C++. You can't pass
why any parameter type T (which has the form U*, a pointer to anything),
cannot be passed by reference. It doesn't matter whether U is an array type
or not.
a pointer to function that takes an array passed by reference. You can,
of course, pass a pointer by reference, but that is neither here nor
there.
In C++, you can't pass arrays as parameters at all - the language inherited
C's handling of arrays. You can, of course, pass objects of std::array<>
type by value or by reference, just like any other class types.
consider references as values that are passed by, err..., value. But
you seem prepared to accept that some things can be "passed by reference"
in C++.
So if this:That's backwards compatibility with C array handling at play. I personally would use std::array<int, 10> here, and pass that by reference (or pass a reference to it, if that is a more accurate description).
#include <iostream>
void g(int &i) { std::cout << i << "\n"; }
int main(void)
{
int I{0};
g(I);
}
shows an int object, I, being passed to g, why does this
#include <iostream>
void f(int (&ar)[10]) { std::cout << sizeof ar << "\n"; }
int main(void)
{
int A[10];
f(A);
}
not show an array, A, being passed to f?
As I said, I don't think it's wise to look at it this way, but I am just
borrowing your use of terms to try to tease out what you are getting at.
Les messages affichés proviennent d'usenet.