On 2008-02-16 16:58:58 -0500, Lilith
> On Sat, 16 Feb 2008 13:32:08 -0700, Jerry Coffin
> wrote:
>
>> In article
>> lilith@dcccd.edu says...
>>
>> [ ... ]
>>
>>> Essentially I have a context in which at makes
>>> sense to have a class object return an integer value when the object's
>>> name is used.
>>>
>>> class X {
>>>
>>> int XNumber;
>>
>> [ ... ]
>>
>> operator int() { return XNumber; }
>>
>> Keep in mind that this allows implicit conversion of an X to an int,
>> even when you may not want that. Conversion operators can be handy, but
>> they can also be somewhat dangerous.
>
> 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.
A rule of thumb that I used to determine if conversion operator should
be used or not, is to ask myself if my class and the conversion type
obey the "is a" relationship in an object oriented fashion.
So, my question to you is this: is your class X an integer, in the OOP sense?
--
// kira