c++ - A vector of pointers to objects that may or may not exist -
here's problem: making game using sfml, , wanted have vector of sf::drawable* windowmanager.add(randomgamesprite), problem have want able have can delete randomgamesprite without having manually remove pointer window. there way have check see if object exists before trying draw it?
i using c++11, smart pointers haven't been much help in i've tried. tried using std::shared_ptr, keeps drawables alive.
you store weak_ptr<t>
in vector. weak pointer not maintain object alive: if shared pointers object go out of scope, weak pointer automatically expire.
c++ pointers vector
No comments:
Post a Comment