Re: implicit cast operator funny-ness

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Pieter Breed <pieter.breed@xxxxxxxxx> wrote:
Please excuse me, but the bulk of my post will be a code post. It
describes some weirdness with regards to the implicit casting operator.
The crux of the problem is this:

I want to set a property on a class that takes an interface instance.
I have a class that can cast implicit to a class that impliments said
interface,
but the compiler moans and says it cannot cast implicitly like that.

My question is why? Why does this make sense to work like this?

I suspect the problem is that while there's an implicit conversion from
WithOperator to BImpl, and an implicit conversion from BImpl to BI,
that doesn't mean there's an implicit conversion from WithOperator to
BI. Once you do the cast, there's only one conversion left to do.

I can check the specs in this regard if you want, but I don't guarantee
to be able to do it any time soon - it can be quite dense reading in
terms of conversions.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages