问题描述
我想为发射信号到插槽的模块(线程)创建一个包装类boost :: signals2。也就是说模块应该通过继承我的Signal类来获得典型的简单信令能力(例如公共连接(...)方法)。我还想隐藏所使用的实际信号时隙实现。
I would like to create a wrapper class for boost::signals2 for modules (threads) that emits signals to slots. I.e. a module should gain typical simple signalling capabilities (e.g. a public connect(...) method) by inheriting from my Signal class. I would also like to hide the actual signal-slot implementation that is used.
一个具体的插槽继承自一个通用的Slot基类,它具有定义其签名的模板参数。
A concrete slot inherits from a generic Slot base class which has a template parameter defining its signature. A slot is just a functor with the suitable signature.
这个问题在某种程度上与。
This question has been answered in a different context here.
实际上,必须使用std :: ref或boost :: ref,因为boost :: signals2 connect方法会复制其参数。但类Slot是不可复制的,因为它是一个抽象类。因此,使用boost :: ref是推荐的解决方案,因为它使插槽可复制。
Actually std::ref or boost::ref have to be used because boost::signals2 connect method copies its arguments. But the class Slot is not copyable as it is an abstract class. Hence using boost::ref is the recommended solution because it makes the slot copyable.
这篇关于包装的boost :: signals2与终身管理的通用插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!