🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Global conversion function names / type casts (templates!) ...

#1774
From: John Max Skaller
Date: Tue, 15 Aug 1995 02:54
42 lines
1798 bytes
In article <DD1MI7.C8H.0.-s@cs.vu.nl>, ctv <ctv@cs.vu.nl> wrote:
>
>Operator overloading can be used to implement so called smart
>pointers. Operator "=", "->", etcetera member functions allow
>these smart pointers to be used in (almost) the same way as real
>pointers.
>
>How to mimic real-pointer-like casts when the pointers are actually
>smart pointers ?

Member templates:

template<class T> class Smart {
T *data;
public:
template<class Q>
Smart(Smart<Q> const &arg) {
data = arg.data; // conversion!
}
..
};

struct Base {};
struct Derived : Base {};
Smart<Derived> pd = new Derived;
Smart<Base> = bd; // Smart pointer conversion!
Smart<Derived> bad = pb; // INSTANTIATION FAILS!

Note in the last line the conversion is CORRECT -- there's
no error here, the error occurs instantiating the
member template. If the body isn't visible you'd not
find out until link time.

--
JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA	    Phone: 61-2-566-2189
---
[ 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: <40ntbc$q68@metro.ucc.su.OZ.AU>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <DD1MI7.C8H.0.-s@cs.vu.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 15 Aug 95 02:54:01 GMT
Approved: fjh@cs.mu.oz.au
Return-Path: <daemon@ncar.UCAR.EDU>
From: maxtal@Physics.usyd.edu.au (John Max Skaller)
Newsgroups: comp.std.c++
Subject: Re: Global conversion function names / type casts (templates!) ...
X-Original-Date: 14 Aug 1995 16:24:12 GMT
Organization: School of Physics, University of Sydney, Australia
Message-ID: <40ntbc$q68@metro.ucc.su.OZ.AU>
References: <DD1MI7.C8H.0.-s@cs.vu.nl>