Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

type erasure problem, correctly up casting from void*

3 views
Skip to first unread message

Sebastian Karlsson

unread,
Nov 18, 2009, 1:39:17 PM11/18/09
to
Hi,

I have a system which handles arbitrary types, and to be able to
invoke the correct functions I use type erasure with a void* argument.
This works dandy most of the time, save for when the type inherits
from multiple types, in which case it naturally fails spectacularly.
So, somehow I must either change the interface to not use void*, in
which case I have problems to create a valid base to overload. Or,
somehow automatically at runtime correctly patch the pointer so that
the cast succeeds. I'm using std::typeinfo already, so that could
perhaps be passed along and inspected, but I can't seem to find any
functionality to do something useful with the typeinfo save for
testing against it and printing the name. Would love to get some
suggestions for a clean solution which hopefully doesn't require to
much explicitly provided information from client code.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

CornedBee

unread,
Nov 19, 2009, 10:53:25 AM11/19/09
to
On Nov 18, 7:39 pm, Sebastian Karlsson <sair...@gmail.com> wrote:
> Hi,
>
> I have a system which handles arbitrary types, and to be able to
> invoke the correct functions I use type erasure with a void* argument.
> This works dandy most of the time, save for when the type inherits
> from multiple types, in which case it naturally fails spectacularly.

Try Boost.Any.

Sebastian

0 new messages