Signal amplification and class transfer method

I defined some signal:

typedef boost::signals2::signal<void (int temp)> SomeSig;
typedef SomeSig::slot_type SomeSigType;

I have a class:

class SomeClass
{
   SomeClass()
   {
     SomeSig.connect(&SomeClass::doMethod);
   }
   void doMethod(const SomeSig &slot);
};

And it turned out a lot of errors:

error: ‘BOOST_PP_ENUM_SHIFTED_PARAMS_M’ was not declared in this scope
error: ‘T’ was not declared in this scope
error: a function call cannot appear in a constant-expression
error: a function call cannot appear in a constant-expression
error: template argument 1 is invalid
error: ‘BOOST_SIGNALS2_MISC_STATEMENT’ has not been declared
error: expected identifier before ‘~’ token
error: expected ‘)’ before ‘~’ token
error: expected ‘;’ before ‘~’ token

UPD : New code (same error):

typedef boost::signals2::signal<void (int keyCode)> SigKeyPressed;
typedef SigKeyPressed::slot_type SigKeyPressedType;

class SomeClass
{
        SigKeyPressed mSigKeyPressed;

    public:
        SomeClass() { mSigKeyPressed.connect(&SomeClass::keyPressed); }
        void keyPressed(const SigKeyPressedType &slot);
};
+3
source share
3 answers

Both Paul and Kit are true (+1 for both). SomeSig is a type, you cannot call a type. You must create an instance of SomeSig. You must also point to an object pointer when using method function pointers. _1 is the place that is required during binding, indicating that the associated function pointer of the method requires one argument.

typedef boost::signals2::signal<void (int keyCode)> SigKeyPressed;
typedef SigKeyPressed::slot_type SigKeyPressedType;

class SomeClass
{
        SigKeyPressed mSigKeyPressed;

    public:
        SomeClass() { mSigKeyPressed.connect(boost::bind(&SomeClass::keyPressed, this, _1); }
        void keyPressed(const SigKeyPressedType &slot);
};
+4
source

Use boost :: bind.

SomeSig.connect(bind(&SomeClass::doMethod, this, _1));

, this, .. - . , .

+3

SomeSig is a type, not an object. You need to identify the signal object and call a connection to this object. In addition, doMethod()the slot parameter type was incorrect.

class SomeClass
{
  SomeClass()
  {
    signal.connect(&SomeClass::doMethod);
  }
  void doMethod(const SomeSigType &slot);
private:
    SomeSig signal;

};

+2
source

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


All Articles