有没有办法让插槽连接到信号?即,我想将信号的槽从一个类的一个实例复制到另一个
我的课堂上有一个信号并遇到以下错误。这可能是因为这个类在 STL 容器中使用。
1>c:\boost_1_52_0\boost\signals\detail\signal_base.hpp(150): error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'
1> c:\boost_1_52_0\boost\noncopyable.hpp(27) : see declaration of 'boost::noncopyable_::noncopyable::noncopyable'
1> c:\boost_1_52_0\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable_::noncopyable'
1> This diagnostic occurred in the compiler generated function 'boost::signals::detail::signal_base::signal_base(const boost::signals::detail::signal_base &)'
1> test.cpp
所以,我决定放置一个复制构造函数并将信号连接到参数信号的插槽,然后我得到以下错误,
1>d:\workarea\boostsignalsEx\test.h(26): error C2663: 'boost::signal1<R,T1>::connect' : 2 overloads have no legal conversion for 'this' pointer
1> with
1> [
1> R=void,
1> T1=int
1> ]
如果我删除复制构造函数参数的 const 限定符,我会得到另一个错误..
1>d:\workarea\boostsignalsEx\test.h(40): error C2558: class 'test' : no copy constructor available or copy constructor is declared 'explicit'
这是我正在处理的示例代码
class test{
public:
boost::signal1<void, int> sig;
test(const test& t) { t.sig.connect(sig);};
void attach(boost::function1<void, int> f) {sig.connect(f);}
};
猜测链接信号将不起作用,因为我不确定复制构造函数参数对象是否会存活“this”对象