Lets say I have a class Handler with some subclasses like stringhandler, SomeTypeHandler, AnotherTypeHandler. The class Handler defines a method "handle" as a common interface for all the subclasses. The logic to "handle" is ofcourse completely different for the different handlers.
So what I need to do is pass a value of anything to the handle method. The specific classes can then cast the "anything" to the type they expect.
Basically what I need is something like the java class Object :D
The first thing I tried was a void*
, but apparently you can not do B* someB = dynamic_cast<B*>(theVoidPointer)
, so no luck there.
My second idea was to use boost::any
. however, the requirement to use boost::any is that the value must be copy cunstructable, which is not the case for my data.
Any ideas to get this to work?
Thanks
EDIT: Note that I know I could use a SomeData class with no members at all, and let my data be subclasses of that, but I am looking for a more generic approach which does not require me to make my own wrapper class.