Article View: comp.std.c++
Article #2380Re: auto_ptr<T> as function return type
From: David Vandevoorde
Date: Wed, 01 Nov 1995 03:54
Date: Wed, 01 Nov 1995 03:54
31 lines
1840 bytes
1840 bytes
>>>>> "IW" == <ian> writes: IW> Some recent comments in this newsgroup indicate that there is some IW> problem with returning an auto_ptr from a function. I was not IW> aware of this; the April 1995 working paper does not mention it IW> and it is not obvious to me why there should be a problem other IW> than the overhead of constructing and destroying a temporary IW> object. Could somebody better informed than I am explain what the IW> issue is? My apologies if this has been discussed before; I missed IW> it. [...] AFAIK, the problem is not so much with returning an auto_ptr as what can be done with the return value (not much). The signatures of the copy constructors and operator='s (which take non-const auto_ptr's) are incompatible with the rvalue character of function return values. Hence, auto_ptr<double> f(); auto_ptr<double> p(f()); // Ah no, copy-ctor take // non-const reference :( and similarly: auto_ptr<double> p; p = f(); // Trouble again... Daveed --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<VANDEVOD.95Oct31222003@juicer.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<47616o$lvr@bcarh8ab.bnr.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 01 Nov 95 03:54:32 GMT Approved: fjh@cs.mu.oz.au From: vandevod@cs.rpi.edu (David Vandevoorde) Newsgroups: comp.std.c++ Subject: Re: auto_ptr<T> as function return type X-Original-Date: 01 Nov 1995 03:20:03 GMT Organization: RPI Computer Science Message-ID: <VANDEVOD.95Oct31222003@juicer.cs.rpi.edu> References: <47616o$lvr@bcarh8ab.bnr.ca> In-Reply-To: "ian's message of 31 Oct 1995 21:25:28 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMJbviuEDnX0m9pzZAQGlmQGAli3fL90S+wjlMVz4V9UHmpuwXjWcHUjm d503dv80GYUxMZeEyo2pW3ZkR7YTSEid =6Rsm