From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-12-11 11:05:11
>From: "Eric Woodruff" <Eric.Woodruff_at_[hidden]>
> "Johan Nilsson" <johan.nilsson_at_[hidden]> wrote in message
> Anyhow, in my opinion, dynamic_void_cast is completely unnecessary and
> casts away the intent that it is _supposed_ to be a two step and very ugly
> process--the signifier that you have a not-so-good design on your hands.
> Stop trying to code a new messenger.
As Bjarne Stroustrup says in D&E, "Don't fight the type system." You can't
win. :) Casting does indeed tend to be fighting the type system. Sure, you
can do it, but you may end up with switch-on-type code, etc., which, as he
said that some had said it, "has the elegance of C, combined with the
efficiency of Smalltalk." :) And even that was too nice, he said.
I understand you (Johan) want to be able to have generic factories, but then
erasing the type is probably not the way to go, and as has been pointed out
in this thread, void * is type erasure. More or less the only safe thing you
can do with it, is to delete it. You can also cast it back to its original
type, but that requires that you know that type to begin with. It doesn't,
portably, have the possibility to cast to arbitrary type, as you've seen.
As you said it, even COM doesn't use void *, but IUnknown and
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk