Re: what is meant by ?




"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.
>
>


.



Relevant Pages

  • Re: how can i generate warnings for implicit casts that lose bits?
    ... C doesn't have implicit casts. ... the manual speaks of "explicit casts", then what is a cast that is not ... i still haven't heard the magic invocation i make to the gcc compiler ...
    (comp.dsp)
  • Re: help with statistics library
    ... explicit casts are preferable to implicit casts, ... Just a nitpick of your nitpick of his nitpick: a cast is an explicit ... conversion, so "implicit cast" is a contradiction in terms. ... I accept that my preference for this way of avoiding the cast might be ...
    (comp.programming)
  • Re: what is meant by ?
    ... A cast operator supports implicit casts, so this could be written as: ... Prev by Date: ...
    (microsoft.public.vc.language)
  • Re: Clarification on type punning.
    ... Type punning is both more AND less that what's done by a cast ... It's more than what's done by a cast operator, ... sufficient to convert a pointer of one type into a pointer of a ...
    (comp.lang.c)
  • Re: implicit cast operator funny-ness
    ... This is more a comment on the use of an implicit cast operator to ... perform this conversion. ... describes some weirdness with regards to the implicit casting operator. ...
    (microsoft.public.dotnet.languages.csharp)