How to implement a template class with a template-dependent signal element from boost?

I am trying to implement a template class that requires a signal element that depends on the template argument. My first idea was to understand this as follows:

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;
};

This class should be used as:

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 a SignalClass object only inside the constructor. It's just for understanding my problem.)

It is important for me to implement a delegate concept with a template as a signal parameter.

The problem is that the constructor code is not working.

But I found a solution.

If I additionally indicate additional typedefas

typedef typename OnReceive::slot_type slot_type;

and use this parameter for the constructor, for example

PushInputSlot(const slot_type& _slot);

it works. But I do not know why.

I hope someone can help me.

Thanx, Frank

P.S.: stackoverflow, . , ... -)....

+3
1

typename ( , typedef):

-, OnReceive " ", .

: - , - . () , , , . , , .
, :: , , - (typedef ) -- (, , ..). , typename () , , .
, , - --, , . , template - ( ).

+2

Source: https://habr.com/ru/post/1763484/


All Articles