Use boost::ref
(or std::ref
) function to pass such an object by reference:
#include <iostream>
#include <boost/signals2.hpp>
#include <boost/ref.hpp>
struct Noncopyable
{
Noncopyable() {};
void operator()() { std::cerr << "hi Noncopyable" << std::endl; }
private:
Noncopyable(Noncopyable const&);
};
int main(void)
{
Noncopyable no_copy;
boost::signals2::signal<void ()> sig;
sig.connect(boost::ref(no_copy));
sig();
}
Of course, ensure that no_copy
object lives at least as long as it's connected to sig
.