I have a scene graph, all nodes deriving from a base class AbstractNode
. AbstractNode
has a registerChild
member function:
registerChild<T>(string name, shared_ptr<AbstractNode> * childMember)
used for registering the children in a standard way (so that they can be listed and modified in the base class interface). It basically adds the name/child_pointer pair to a hash.
So for instance the class material will be declared like that (shortened):
class Material : public AbstractNode
{
public:
Material() { registerChild(&color); }
private:
std_shared<Color> color;
}
Color being another subclass of AbstractNode.
Now I would like to implement a copy constructor for AbstractNode. It must copy the list of registered children, and update the child member pointers. I would like to avoid reimplementing the copy constructor in all base classes. Is this possible?
I have thought of working on pointer offsets, between this
and the child pointers. But are these guaranteed to be constant between two instances? It seems like a big hack to me... (And I'm even sure that this is not guaranteed when subclassing)
Thanks,
Etienne