[英]C++ boost signals and slots with different parameters?
Can a C++ signal be linked to slots with different parameter lists? 可以将C ++信号链接到具有不同参数列表的插槽吗?
ie one slot takes 1 parameter, the other one takes 2, etc... 也就是说,一个插槽需要1个参数,另一个插槽需要2个,依此类推...
And you then call that signal with 1 or 2 parameters and it calls the corresponding slot? 然后使用1或2个参数调用该信号,然后调用相应的插槽?
No, the arity of a signal
instance is defined by its type. 不,
signal
实例的类型由其类型定义。 If you examine the definition of the boost::signals2
template class (or the deprecated boost::signals
): 如果您检查
boost::signals2
模板类的定义(或不建议使用的boost::signals
):
template<typename Signature,
typename Combiner = boost::signals2::optional_last_value<R>,
typename Group = int, typename GroupCompare = std::less<Group>,
typename SlotFunction = boost::function<Signature>,
typename ExtendedSlotFunction = boost::function<R (const connection &, T1, T2, ..., TN)>,
typename Mutex = boost::signals2::mutex>
class signal : public boost::signals2::signal_base {
The calling signature of the signal and its slots are fixed in the template parameters. 信号的呼叫签名及其时隙固定在模板参数中。
A workaround would be to define an Event
argument type that can contain multiple kinds of data, eg defined by subclasses. 一种解决方法是定义一个
Event
参数类型,它可以包含多种数据,例如,由子类定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.