Being a value semantic language, C++
passes all parameters by value. So when I pass pointer to an object, the object is passed by reference, but the pointer
itself is passed by value (although I believe the object is not passed at all, only the pointer
is, and we access the object inside the function by reference. I think this idea also conform to value semantics, since if I thinks like this, value semantics becomes more meaningful, Nothing is passed except value).
So thinking this way makes sense for pointer
, as a pointer
to something is itself an object, which has both lvalue
and rvalue
. While passing a pointer
as a parameter, a copy of the rvalue
is sent, like any other object (ex. passing an integer).
But what about reference
? Theoretically, reference
is not any individual object, id does not have any identity, simply an alias to the object it refers to. Common implementation of reference
may be on top on pointer
, but what about uncommon implementation? Even if implemented in terms of pointer
, is it passed by value?