class Whatever
{
public:
virtual ~Whatever();
protected:
Whatever();
virtual void SomeMethod();
void OnEventOccurred(int x);
std::vector<boost::signals2::scoped_connection> boostSignalConnections_;
}
// .cpp
Whatever::SomeMethod()
{
...
boostSignalConnections_.push_back(
anObject->AddEventOccurredObserver(
std::bind(&Whatever::OnEventOccurred,
this, std::placeholders::_1)));
...
}
(Note AddEventOccurredObserver
just delegates to boost::signals2::connect()
and returns the boost::signals2::connection
)
I'm getting the following error. It's hard to interpret template errors but it seems like the error is being caused at the member declaration of std::vector<boost::signals2::scoped_connection> boostSignalConnections_;
...\vc\include\xmemory(202): error C2248:
'boost::signals2::scoped_connection::scoped_connection' :
cannot access private member declared in class 'boost::signals2::scoped_connection'
...\boost_1_47\boost\signals2\connection.hpp(234) : see declaration of
'boost::signals2::scoped_connection::scoped_connection'
...\boost_1_47\boost\signals2\connection.hpp(210) :
see declaration of 'boost::signals2::scoped_connection'
...\vc\include\xmemory(201) : while compiling class template member function
'void std::allocator<_Ty>::construct(boost::signals2::scoped_connection *,_Ty &&)'
with
[
_Ty=boost::signals2::scoped_connection
]
I've searched and I think it might have to do with scoped_connection not being copyable? I'm not sure. The reason I'm using a scoped_connection is because of this SO question: Handle connection/disconnection of many signals/slots with boost::signals2
Update
FYI, when I change from scoped_connection
to connection
it works: std::vector<boost::signals2::connection> boostSignalConnections_;
. My whole reason for using scoped_connection
is that they automatically disconnect the connection on destruction whereas I believe a connection
doesn't not. However, I can just iterate over the collection and manually disconnect each one.