Reputation: 345
Can a C++ signal be linked to slots with different parameter lists?
i.e. one slot takes 1 parameter, the other one takes 2, etc...
And you then call that signal with 1 or 2 parameters and it calls the corresponding slot?
Upvotes: 0
Views: 861
Reputation: 15841
No, the arity of a signal
instance is defined by its type. If you examine the definition of the boost::signals2
template class (or the deprecated 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, e.g. defined by subclasses.
Upvotes: 2