I am trying to find a better way to hold a pointer to an element in a vector that has just been created and added to a member variable vector:
SceneGraphNode* addChild(std::string name){ SceneGraphNode child(this,name); m_children.push_back(child); return &child; }
The compiler rightfully gives me a warning, since I am returning the address of an object created on the stack, and this object goes out of scope as the function completes. However, the object lives in vector , right?
So, should I ignore the warning, or is there a better way to do this?
source share