Handle connection/disconnection of many signals/slots with boost::signals2

后端 未结 2 1195
粉色の甜心
粉色の甜心 2021-01-20 00:13

I\'ve started using boost::signals2 instead of my old signals-code. I\'m having a problem with administering multiple connections though. Here\'s my problem:

I have

2条回答
  •  离开以前
    2021-01-20 00:26

    What about:

    class PeopleBrowser
    {
    public:
        void AddPerson (Person& p)
        {
            name_change_connections[&p] = p.NameChange.connect(...);
        }
        void RemovePerson(Person& p)
        {
             name_change_connections.erase(&p);
        }
    
    private:
        std::map name_change_connections;
    };
    

    You might also want to take a look at automatic connection management.

提交回复
热议问题