Thread View: comp.std.c++
3 messages
3 total messages
Started by Jean-Louis Moser
Wed, 11 Oct 1995 17:27
Q: auto_ptr
Author: Jean-Louis Moser
Date: Wed, 11 Oct 1995 17:27
Date: Wed, 11 Oct 1995 17:27
26 lines
1436 bytes
1436 bytes
I got the implementation of auto_ptr in the draft standard
- Is there a reason why the method operator=(T*) isn't
implemented.
- Why operator= doesn't respect the classical sementic of
this operator, returning T* to enable: p1 = p2 = p3;
- With this implementation it's not possible to build auto_ptr
on const T*, because constructor takes a T* as argument.
jlm
ps: Could somebody give me pointers to good publications
on "all about reference counting and smart pointers"
--
+----------------------------+------------------------------------+
| Jean-Louis Moser | 2001 SA |
| tel: 33 (1)46.66.54.54 | 2, rue de la renaissance |
| Email: jlm@two-oo-one.fr | F-92184 Antony Cedex |
+----------------------------+------------------------------------+
---
[ 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. ]
Re: Q: auto_ptr
Author: J. Kanze
Date: Fri, 13 Oct 1995 08:26
Date: Fri, 13 Oct 1995 08:26
51 lines
2075 bytes
2075 bytes
Jean-Louis Moser (jlm@two-oo-one.fr) wrote:
|> I got the implementation of auto_ptr in the draft standard
|> - Is there a reason why the method operator=(T*) isn't
|> implemented.
Not that I know of.
|> - Why operator= doesn't respect the classical sementic of
|> this operator, returning T* to enable: p1 = p2 = p3;
Because returning T* wouldn't work anymore than the classical solution
(returning auto_ptr< T >&).
Returning T* in the above example would result in both p1 and p2 owning
the pointer.
Returning auto_ptr< T >& would cause the above to have strange
semantics. Since the operator= also modifies the right hand side, this
would be the equivalent of:
p1 = p3 ;
p2 = 0 ;
|> - With this implementation it's not possible to build auto_ptr
|> on const T*, because constructor takes a T* as argument.
Sure it is, for any given T. Try it: auto_ptr< int >, T == int;
auto_ptr< const int >, T == const int.
What you cannot do is the following:
auto_ptr< int > p( new int ) ;
auto_ptr< const int > pc( p ) ;
Unlike real pointers, there is no automatic conversion from pointer to
int to pointer to const int.
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
--Beratung in industrieller Datenverarbeitung
---
[ 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. ]
Re: Q: auto_ptr
Author: Alex Martelli
Date: Sun, 15 Oct 1995 14:39
Date: Sun, 15 Oct 1995 14:39
20 lines
1341 bytes
1341 bytes
gregor@netcom.com (Greg Colvin) writes:
...
> #if HAS_MEMBER_TEMPLATES
...
> template<class Y> auto_ptr& operator=(auto_ptr& r) {
I think this is meant to be "operator=(auto_ptr<Y>& r)", similarly
to the copy-ctor just above, yes?
Alex
--
DISCLAIMER: these are TOTALLY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it Phone: +39 (51) 597313
CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia Fax: +39 (51) 597120
[ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads