-
August 21st, 2014, 02:52 AM
#14
Re: passing smart pointer
speaking of sterile back and forth arguments ...
Originally Posted by razzle
This terminology is upheld both by Stroustrup in The C++ Programming Language and by the C++ standard
nowhere in the standard the expression "pass by reference" is used, probably because it's a rather useless and ambiguous terminology on its own; actually, the expression "reference semantics" is (rarely) used meaning exactly what predicatenormative meant, that is the contract of a type ( be it a reference, pointer, proxy, ... ) of "referencing" some other object.
Indeed, nothing would have prevented the language designers to define a special pointer modeling a "T*const" with the same stronger aliasing guarantees of references and, conversely, nothing prevents the definition of more "object-like" references ( indeed, the standard does define a copy-assignable reference wrapper exactly to implement reference semantics for some STL algos ). Basing an "established terminology" on a syntactical accident does not make much sense to me.
Strictly speaking, for every function "f(T y){...}" the expression "f(x)" is equivalent to "{T y = x; ...}" wrt parameter initialization, that is there's only one "parameter passing mechanism" in c++, namely so called copy-initialization of the parameters, whatever their types are. The semantics of the parameter is more important IMO and it's conveyed by the type ( or by the context if the type is not sufficiently well-purposed, as monarch_dodra said ).
Originally Posted by razzle
The purpose of the established terminology is to make a distinction strictly limited to the actual parameter passing.
either you're wrong and the meaning is more semantical than syntactical ( this is how I've always read it BTW ) or you're right and that terminology has poor conceptual and practical utlity. I don't know ...
Last edited by superbonzo; August 21st, 2014 at 02:57 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|