I am working with a node tree and I want to copy a node and all of it's children but I can't because of polymorphism.
class Node
{
Node(const Node& other)
{
// not sure what to do
}
~Node() virtual
{
for (auto child: children)
delete child;
}
vector<Node*> children;
}
class Node1
{
// node1
}
class Node2
{
// node2
}
Children in node is a mix of node1 and node2.
I have tried using new Node exception that does not work because then it does not have enough space for the polymorphised nodes. The only way that I can think to do this is with malloc but that seems a little crude.