M
MathStuf
I am building a class which is like a tree of sorts. Each node can
hold numerous subnodes of itself. I have some constructors such as:
Node(string name, int value);
Node(string name, string value);
I would also like the following AddNode methods:
AddNode(Node &node);
AddNode(string name, int value);
AddNode(string name, string value);
The AddNode where another node is passed works fine. However, the ones
where new values are passed doesn't when set up as such:
AddNode(string name, int value)
{
Node add(name, value);
elements.push_back(add);
return &elements[elements.size() - 1];
}
I know it's because the instance of the new Node is temporary, but is
there a way to keep it around for future use?
--MathStuf
hold numerous subnodes of itself. I have some constructors such as:
Node(string name, int value);
Node(string name, string value);
I would also like the following AddNode methods:
AddNode(Node &node);
AddNode(string name, int value);
AddNode(string name, string value);
The AddNode where another node is passed works fine. However, the ones
where new values are passed doesn't when set up as such:
AddNode(string name, int value)
{
Node add(name, value);
elements.push_back(add);
return &elements[elements.size() - 1];
}
I know it's because the instance of the new Node is temporary, but is
there a way to keep it around for future use?
--MathStuf