Re: what is meant by ?
- From: "Peter Koch Larsen" <pkl@xxxxxxxxx>
- Date: Fri, 15 Apr 2005 10:52:33 +0200
"Frank Hickman [MVP]" <fhickman_NOSP@xxxxxxxxxxxxxxx> skrev i en meddelelse
news:%23rKPSgWQFHA.612@xxxxxxxxxxxxxxxxxxxxxxx
> "Jerry Coffin" <jcoffin@xxxxxxxxx> wrote in message
> news:MPG.1cc822955676a33198969b@xxxxxxxxxxxxxxxxxxxxx
>> In article <#YYLaNNQFHA.1176@xxxxxxxxxxxxxxxxxxxx>,
>> fhickman_NOSP@xxxxxxxxxxxxxxx says...
>>
>> [ ... ]
>>
>>> >> int j= (int)some_class_that_implements_the_int_cast_operator;
>>> >
>>> > Well - you surely did not want that C-style cast there, did you?
>>
>> [ ... ]
>>
>>> Sure I did, how else would the example have been written? Or would
>>> using
>>> static_cast have pleased you more? ;)
>>
>> A cast operator supports implicit casts, so this could be written as:
>>
>> int j = some_class_that_implements_the_int_cast_operator;
>>
>> Proxy classes use this behavior heavily. Nicely enough, it "uses up"
>> the one implicit cast allowed on any particular item, so any other
>> conversion must be explicit.
>>
>> --
>> Later,
>> Jerry.
>>
>> The universe is a figment of its own imagination.
>
> I see your point, it was more or less my programming style because I tend
> to write code explicitly for clarity. You know 6 in one half dozen in the
> other :)
So you claim that
int j= (int)some_class_that_implements_the_int_cast_operator;
is clearer than
int j= some_class_that_implements_the_int_cast_operator; ?
I disagree - the cast just muddles things up. What if the class did not
implement the int-cast? I surely would feel much better using the second
assignment listed. When a cast is not needed, don't use it. In particular
NEVER use a C-style cast.
/Peter
>
> --
> ============
> Frank Hickman
> Microsoft MVP
> NobleSoft, Inc.
> ============
> Replace the _nosp@m_ with @ to reply.
>
>
.
- References:
- what is meant by ?
- From: IceColdFire
- Re: what is meant by ?
- From: Frank Hickman [MVP]
- Re: what is meant by ?
- From: Peter Koch Larsen
- Re: what is meant by ?
- From: Frank Hickman [MVP]
- Re: what is meant by ?
- From: Jerry Coffin
- Re: what is meant by ?
- From: Frank Hickman [MVP]
- what is meant by ?
- Prev by Date: Re: Trapping First-Chance Exception
- Next by Date: Re: Accessing members in array
- Previous by thread: Re: what is meant by ?
- Next by thread: Re: what is meant by ?
- Index(es):
Relevant Pages
|