增强信号连接管理 [英] boost signals connection management

查看:89
本文介绍了增强信号连接管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的两个晚上,我一直在head头,试图解决这个问题,但没有取得积极的结果.事情是这样的,在升压信号中,每次我想将一个类的成员函数连接到另一个类的信号时,如果要稍后断开连接,就必须将结果连接保存在变量中.如果稍后,我想将相同的成员函数连接到其他某个类信号(该成员函数仍与先前的类信号连接),我必须保存此新连接以便对其进行管理.我的问题是,有什么办法可以避免这种情况?

I've been bashing my head for the last two nights trying to figure this out with no positive results. There is the thing, in boost signals, every time I want to connect, say, a member function of one class to another's class signal, I have to save the resulting connection in a variable if I want to disconnect later. If later on, I want to connect the same member function to some other class signal (the member function is still connected with the previous class signal) I have to save this new connection in order to manage it too. My question is, is there any way to avoid this?

推荐答案

您不需要保留connection实例,您应该能够通过将原始可调用对象传递给signal::disconnect来与信号断开连接,例如在 Boost.Signals教程中进行了介绍.使用成员函数时,问题就在于您无法将它们直接传递给signal,或者将它们包装在自定义函数对象中,然后将其用作signal::disconnect的参数,或者使用 Boost一起使用来解决该问题.功能.

You shouldn't need to keep connection instances around, you should be able to disconnect from a signal by passing the original callable to signal::disconnect, as described in the Boost.Signals tutorial. With member functions the problem is rather the fact that you cannot pass them directly to signal, you either wrap them in custom function objects, which would then be available as arguments to signal::disconnect or you use Boost.Bind, which by itself wouldn't be very useful as you cannot conveniently declare its return type. However that problem can be solved using Boost.Bind together with Boost.Function.

我希望我回答了你的问题.

I hope I answered your question.

这篇关于增强信号连接管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆