Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-04-25 09:28:24

"Peter Dimov" <pdimov_at_[hidden]> wrote in message
> From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> > True, but what is the semantic of an implicit conversion?
> > In particular, if under a given circumstance, a static_cast<> yields the
> > wrong value, how could a conversion without a cast do it right? If the
> > compiler knows how to do it right for the implicit conversion (or for
> > other conversion/cast without RTTI), then it would
> > certainly do it right for the static_cast<> too, wouldn't it?
> How could the implicit conversion yield the wrong value? C++ would be
> unusable. static_cast can yield the wrong value only when downcasting, but
> this is an upcast, the pinnacle of IS-A etc.

Oops, I meant "upcast" in my reply, which is the case we are considering,
not "downcast" :-) (That is, from Derived* to Base*)

I think (or thought, perhaps) that any non-dynamic conversion along a
hierarchy, whatever the direction, is only guaranteed to yield the correct
value iif the hierarchy doesn't involve virtual base classes combined with
multiple inheritance (except when upcast is straight to a root type).

I don't think this means that C++ unusable, because we have dynamic_cast<>.
I always use dynamic_cast<> for polymorphic casts regardless the direction
(since the day I discovered Borland doing the upcast wrong with

Anyway, I'm likely wrong because (a) I'm basing this on the particular
behavior of an older version of my compiler, (b) you two couldn't be wrong
at the same time :-)

So, I'm going to embarrass myself asking this on c.l.cpp.m just to make sure
I'm wrong.

Fernando Cacciola
Sierra s.r.l.

Boost list run by bdawes at, gregod at, cpdaniel at, john at