I have a component based scene graph in which a node class can have a derived component added. This derived component is stored in a shared_ptr, but contains no shared_ptr to its parent.

When storing a component I want to extend the lifespan of the node that owns it as well, so my “getComponent” methods return something called a “SafeComponent<T>” which contains both a shared_ptr to the component, and one to the component’s parent node. In this way users can be sure that when they have a SafeComponent handle the node won’t be yanked away while the component still lives.

In short, I have an object called SafeComponent which I want to treat transparently as a Component, its only function is to extend the lifespan of a parent node. I overload the dereference operators to return the shared_ptr, and I want to treat them the same in chaiscript as I do in C++.

In chaiscript I am okay with getting this behavior through simple casting (so I don’t have to explicitly hook up both the ComponentType and the SafeComponent which would be near identical. So my strategy was to use:

To summarize: type_conversion works when trying to cast from one type to another, however, when doing so it will not allow you to directly access base_class exposed methods (only methods directly in the class you’re casting to).