增强信号和传递类方法

Max*_*rai 3 c++ boost signals

我定义了一些信号:

\n\n
typedef boost::signals2::signal<void (int temp)> SomeSig;\ntypedef SomeSig::slot_type SomeSigType;\n
Run Code Online (Sandbox Code Playgroud)\n\n

我有一些课:

\n\n
class SomeClass\n{\n   SomeClass()\n   {\n     SomeSig.connect(&SomeClass::doMethod);\n   }\n   void doMethod(const SomeSig &slot);\n};\n
Run Code Online (Sandbox Code Playgroud)\n\n

并且出现了很多错误:

\n\n
error: \xe2\x80\x98BOOST_PP_ENUM_SHIFTED_PARAMS_M\xe2\x80\x99 was not declared in this scope\nerror: \xe2\x80\x98T\xe2\x80\x99 was not declared in this scope\nerror: a function call cannot appear in a constant-expression\nerror: a function call cannot appear in a constant-expression\nerror: template argument 1 is invalid\nerror: \xe2\x80\x98BOOST_SIGNALS2_MISC_STATEMENT\xe2\x80\x99 has not been declared\nerror: expected identifier before \xe2\x80\x98~\xe2\x80\x99 token\nerror: expected \xe2\x80\x98)\xe2\x80\x99 before \xe2\x80\x98~\xe2\x80\x99 token\nerror: expected \xe2\x80\x98;\xe2\x80\x99 before \xe2\x80\x98~\xe2\x80\x99 token\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

UPD :\n新代码(相同的错误):

\n\n
typedef boost::signals2::signal<void (int keyCode)> SigKeyPressed;\ntypedef SigKeyPressed::slot_type SigKeyPressedType;\n\nclass SomeClass\n{\n        SigKeyPressed mSigKeyPressed;\n\n    public:\n        SomeClass() { mSigKeyPressed.connect(&SomeClass::keyPressed); }\n        void keyPressed(const SigKeyPressedType &slot);\n};\n
Run Code Online (Sandbox Code Playgroud)\n

man*_*est 5

帕维尔和基思都是正确的(两者都是+1)。SomeSig 是一种类型,您不能调用类型。您必须实例化 SomeSig。使用方法函数指针时,还必须提供指向对象的指针。_1 是绑定期间所需的占位符,指示所绑定的方法函数指针需要单个参数。

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);
};
Run Code Online (Sandbox Code Playgroud)