🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2379

Re: auto_ptr<T> as function return type

#2379
From: Fergus Henderson
Date: Wed, 01 Nov 1995 13:22
34 lines
1593 bytes
vandevod@cs.rpi.edu (David Vandevoorde) writes:

>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...

Yep.  With the current spec., you need to write

	auto_ptr<double> p(f().release());

and

	p.reset(f().release());

instead.

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
---
[ 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: <9530600.21749@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <47616o$lvr@bcarh8ab.bnr.ca> <VANDEVOD.95Oct31222003@juicer.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Approved: fjh@cs.mu.oz.au
Date: 01 Nov 95 13:22:57 GMT
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Message-ID: <9530600.21749@mulga.cs.mu.OZ.AU>
Newsgroups: comp.std.c++
Organization: Computer Science, University of Melbourne, Australia
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <47616o$lvr@bcarh8ab.bnr.ca> <VANDEVOD.95Oct31222003@juicer.cs.rpi.edu>
Subject: Re: auto_ptr<T> as function return type
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJd0yOEDnX0m9pzZAQGqEgF/VEEnzo9/XO8baH0tRmpmVAOH0fD3HKMT
 A4DKUuXBaI1IlnKQi5L0h2saATAS63dD
 =Lrv0