Object delete itself from container

后端 未结 4 936
耶瑟儿~
耶瑟儿~ 2021-01-16 15:59

So I have a container(any kind, probably std::map or std::vector) which contains objects of a class with some network thing running in a thread that checks if it is still co

4条回答
  •  北海茫月
    2021-01-16 16:42

    I had a problem very similar to yours, which I solved by emitting a boost::signal from the "network thing" when it detected the disconnection, being caught by the object managing the container. Upon receiving that signal, it would iterate through the container, removing the dead network session from it. It might be worth looking at it here:

    How to make a C++ boost::signal be caught from an object which encapsulates the object which emits it?

    Cheers,

    Claudio

提交回复
热议问题