Group: comp.lang.c++
From: Lilith
Date: Sunday, February 17, 2008 3:34 PM
Subject: Re: Cass object returning a value by name?

On Sat, 16 Feb 2008 23:09:29 +0100, Niels Dekker - no return address
wrote:

>Jerry Coffin wrote:
>> operator int() { return XNumber; }
>
>Basically Jerry is right, but you'd probably want to indicate that the
>conversion does not modify your X object, by adding a "const":
>
> class X {
> int XNumber;
> public:
> operator int () const { return XNumber; }
> };

Got ya.

>Lilith wrote:
>> Many thanks. I anticipated the hazard and have tried think of an
>> instance where this might be a problem but at this time I can't.
>> However, I'll be on the alert as I progress through this development
>> and if it presents a problem I'll go the less intuitive route.
>
>The dangerous thing about those conversion operators is that their
>conversion happens so "implicitly". Fortunately the next C++ Standard
>will allow you to declare the conversion operator as "explicit". But I
>guess your compiler won't support it yet. Anyway, if you want to know
>more, read: "Explicit Conversion Operator Draft Working Paper (revision
>3)", by Lois Goldthwaite, Michael Wong, Jens Maurer, and Alisdair
>Meredith - www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf

Thanks for the link. I'll have a look.

>[Oops, my original reply went to the wrong newsgroup: comp.lang.c It's
>because of a bug in my good old (VERY old) newsgroup client. Hmmm,
>maybe I should upgrade!]

>Kind regards,

--
Lilith

Safety Articles | Usenet Groups | Usenet News | Bluegrass