🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: auto_ptr::reset and auto_ptr::operator=

#1962
From: Scott Howlett
Date: Thu, 14 Sep 1995 02:00
27 lines
1595 bytes
In article <gregorDEtM0t.Hw2@netcom.com>, gregor@netcom.com (Greg Colvin) wrote:

> In article <199509111753.AA15077@xs1.xs4all.nl> veldhuis@xs4all.nl writes:
> >It seems to me that in the assignment a deep copy should be performed in 
> >stead of a binary copy.
> 
> That would require that the type being pointed to have a copy constructor.
> If you wish you can write b.reset(new int(*a)) instead of b = a.
> 

A copy constructor will not suffice in many cases. If a contains an object
of some polymorphic class,you would need to write something akin to
b.reset(a->clone()).

I imagine that this semantic requirement is a sufficient reason for the
_standard_ auto_ptr template not to try to do fancy things like copying its
contents (although it should be easy to derive your own my_auto_ptr template
which does.

-- 
Scott Howlett
Storm Software, Inc.
howlett@netcom.com
---
[ 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: <howlett-1309951102050001@192.0.2.1>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <199509111753.AA15077@xs1.xs4all.nl> <gregorDEtM0t.Hw2@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 14 Sep 95 02:00:22 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
From: howlett@netcom.com (Scott Howlett)
Subject: Re: auto_ptr::reset and auto_ptr::operator=
Message-ID: <howlett-1309951102050001@192.0.2.1>
Sender: howlett@netcom.com (J. Scott Howlett)
Organization: Storm Software, Inc.
References: <199509111753.AA15077@xs1.xs4all.nl> <gregorDEtM0t.Hw2@netcom.com>
X-Original-Date: Wed, 13 Sep 1995 17:54:07 GMT