I try to implement a template class which requires to have a signal member that depends on the template argument. My first idea was to realize it like the following:
template<class T>
class SignalClass
{
typedef boost::signals2::signal<void (T &)> OnReceive;
public:
SignalClass(const OnReceive::slot_type &_slot)
{
m_onReceive.cnnect(_slot);
}
virtual SignalClass(){};
void Send(T &_val)
{
m_onReceive(_val);
}
private:
OnReceive m_onReceive;
};
An that class should be used like:
class SignaledClass
{
public:
SignaledClass(void)
{
SignalClass<int> var1(boost::bind(&SignaledClass::ReceiveINT, this));
SignalClass<double> var2(boost::bind(&SignaledClass::ReceiveDOUBLE, this));
}
void ReceiveINT(int &_val)
{
...
}
void ReceiveDOUBLE(double &_val)
{
...
}
}
(BTW: I know, that it makes no sense to create the SignalClass object just inside the constructor. It's just to understand my problem.)
It is important for me to realize a delegate-like concept with a template as signal parameter.
The problem is that the constructor code doesn't work.
But I found a solution.
If I additionally specify an additional typedef
like
typedef typename OnReceive::slot_type slot_type;
and use that a parameter for the constructor, like
PushInputSlot(const slot_type& _slot);
the it works. But I have no real clue why.
I hope that somebody can help me.
Thanx, Frank
P.S.: I'm new on stackoverflow thats why I'm not familiar with the rules here. Hope I've done everything in the right way... ;-)....