I'm trying to store RectangleNode pointers in a vector. RectangleNode is derived from RootNode.
For some reason, I am able to add a node to the vector but it keeps disapearing when the function exits. I have already spent a lot of time on this issue but I feel it might be something simple I just don't understand.
When I look at the size of the vector I can see that the object is being added but doesn't stay in it as if it gets deleted.
Vector declaration :
vector<RootNode*> childrenNodes;
Where I create the RectangleNode :
switch (appState) {
case RectangleTool: currentNode = root.addChildren(&RectangleNode(x, y, 50, 50));
break;
My method to add nodes to this vector :
RootNode& RootNode::addChildren(RootNode* node)
{
childrenNodes.push_back(node);
cout << childrenNodes.size() << endl;
return *node;
}
Also, I declared RootNode root = RootNode(); in a .h file, and I'm wondering if it's right. When I put it at the top of the .ccp file I have issues.
I'm trying to implement a scenegraph in an openFrameworks application if that helps.
Thanks.
Aucun commentaire:
Enregistrer un commentaire