I would like to write down a set of classes in which there are:
- a pure virtual class that wraps an object of any kind and the relate getter for it.
- one or more classes for every kind of object I need, extending the virtual one and overriding the getter in order to specialize it.
A template class solution for the wrapper seems to fit the case but I have to use it in two different contexts:
- the first one is not aware of wrapper implementations. In this case I should declare a
Wrapper<AnyObj> var;
withAnyObj
standing for any class name (like?
in Java). As far as I know, you can't do this in c++. - the second one is restricted to a particular wrapper implementation. In this case I need the getter to return the wrapped object with the exact type (rather than downcasting it).
If I'm right I cannot use a template class and, moreover, the wrapper won't have a protected: T* wrappedObject
member.
I don't know if I'm stuck in the Java approach, wrongly thinking from the beginning, or missing something.
Any suggestion is appreciated.