在对象上使用信号/槽
我将 boost 库中的信号功能与同一类中的函数一起使用,但现在我想向另一个类中声明的对象发出信号。
在这里:
在我的“inputReader”类中,我有以下功能:
void setNonTraverse(char key, int x, int y);
void setChest(char key, int x, int y);
void setEntry(char key, int x, int y);
void setExit(char key, int x, int y);
在从键盘读取的代码中,我有:
inputReader readInput;
/* This is setting up our signal for sending observations */
boost::signals2::signal<void (char, int, int)> sig;
/* Subjects the Observer will connect with */
sig.connect(bind(&inputReader::setChest, &readInput ));
但是当然..这不起作用..我尝试查看文档,但找不到任何事物。有人可以帮我吗?
I used the signal functionality in the boost library fine with functions in the same class, but now I want to signal an object declared in another class.
Here it is:
in my 'inputReader' class I have the following functions:
void setNonTraverse(char key, int x, int y);
void setChest(char key, int x, int y);
void setEntry(char key, int x, int y);
void setExit(char key, int x, int y);
in my code that reads from the keyboard I have:
inputReader readInput;
/* This is setting up our signal for sending observations */
boost::signals2::signal<void (char, int, int)> sig;
/* Subjects the Observer will connect with */
sig.connect(bind(&inputReader::setChest, &readInput ));
But of course.. this is not working.. I tried looking at the documentation, but couldn't find anything. Can anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
bind
时,您需要为函数采用的任何其他参数添加占位符。在这种情况下,由于您的函数需要 3 个参数:无论您是在同一个类中还是在单独的对象中执行此操作,您都需要它。
When using
bind
, you need to put placeholders for any additional parameters your function takes. In this case, since your function takes 3 parameters:You'd need this whether you're doing it in the same class or from a separate object.