Article View: comp.std.c++
Article #3852Re: Quick questions
From: J. Kanze
Date: Thu, 28 Mar 1996 17:31
Date: Thu, 28 Mar 1996 17:31
42 lines
2693 bytes
2693 bytes
In article <4jajk2$17aq@mule1.mindspring.com> abell@mindspring.com
(Andrew Bell) writes:
|> clamage@Eng.sun.com (Steve Clamage) wrote [but much edited by me]:
|> >In article 1e7a@mule1.mindspring.com, abell@mindspring.com (Andrew Bell) writes:
|> >>About casting operators]
|> >[[Are you asking] can you define
|> >a conversion operator from a user-defined class to a predefined type
|> No, I'd want to go the other way. In the case of "pure wrapper"
|> classes (as I defined in my earlier post), one might want an automatic
|> cast from the original to the wrapper. In my case, I have created a
|> class to wrap around an OS-defined struct, to give it access safety
|> (the particular class contains a type specifier and a union) and
|> smarter access as well as constructors.
You have it the other way. The conversion operator is called a
constructor. Thus, to take a concrete example (based on the deleted
parts of your posting (`stat' is a struct defined by Posix):
class FileStat : stat
{
public :
FileStat( stat const& other ) ;
// ...
} ;
If you have a (C) struct stat, it will convert automatically to a
FileStat. (You can pass it to a function expecting a FileStat, for
example.)
--
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. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<KANZE.96Mar28102433@gabi.gabi-soft.fr>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<4j5b26$1e7a@mule1.mindspring.com> <4j7a64$l9i@engnews1.Eng.Sun.COM> <4jajk2$17aq@mule1.mindspring.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.std.c++
Subject: Re: Quick questions
Date: 28 Mar 1996 09:31:19 PST
Organization: GABI Software, Sarl.
Approved: austern@isolde.mti.sgi.com
Message-ID: <KANZE.96Mar28102433@gabi.gabi-soft.fr>
References: <4j5b26$1e7a@mule1.mindspring.com> <4j7a64$l9i@engnews1.Eng.Sun.COM>
<4jajk2$17aq@mule1.mindspring.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 28 Mar 1996 09:24:33 GMT
In-Reply-To: abell@mindspring.com's message of 27 Mar 1996 15:46:56 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
iQBVAwUBMVrM6Uy4NqrwXLNJAQHJfgH/SsWrCD8cbqOdf6iYa2Rq+I80Hly4E55w
yHk4SBicgvldmKLtF/zXqfBqt3hIlFAEb7hsKZYPofFH9kret75IRQ==
=Hkye
Originator: austern@isolde.mti.sgi.com