Talk:Language Comparison Table: Difference between revisions

T != T&
(C++ definitely has passing by reference)
(T != T&)
Line 29:
</cpp>
: Note that the explanation for C++ references in [[Parameter Passing]] is not correct: Objects are not ''converted'' to references, they are ''bound'' to references. Reference types in C++ are fundamentally different to all other types, as they do ''not'' denote objects, but, well, references to objects. The references themselves are not objects (you cannot have a pointer or reference to them, you cannot assign them — using them on the left hand of an assignment assigns to the object they refer to —, you cannot determine their size, etc.). Logically they just give a name to an existing object (the compiler may store the address to the object named by the reference, but that's an implementation detail). --[[User:Ce|Ce]] 13:15, 5 August 2008 (UTC)
 
:: Reference T& is a data type distinct from T. As such it has values and objects of its own. The semantics of reference values is such that they refer to objects of T. Reference objects are passed by their values. For the example you provided, consider:
 
::<cpp>
::int A;
::int& B = A;
::
::Foo (B); // The object B is passed to Foo, by its value
::Foo (A); // The object A has to be converted because formal and actual types differ
::B = A; // Reference assignment (defined as deep copy)
::</cpp>
 
:: The issue that some operations (like operator&) might not be pre-defined on the type T& is irrelevant. It does not have operator* as well. But assignment is defined on a LHS reference, as the code sample shows. This is why B = A; is perfectly legal when B is of int& and A is of int. When a reference like B is declared, this is a declaration of an object B. [[C++]] is a typed language, thus B need to have a type. This type is obviously not T, it is T&. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 13:55, 5 August 2008 (UTC)