简体   繁体   English

从列表中删除回调函数?

[英]Remove callback function from list?

Okay, I have a list of callbacks, Callback is defined as follows: 好的,我有一个回调列表,Callback定义如下:

typedef std::function<void(Event*)> Callback;

Now If I try to remove an object from that list via 现在,如果我尝试通过该列表中删除对象

callbackBindings[index].remove(callback);

I get 我明白了

Error 100 error C2248: 'std::function<_Fty>::operator ==' : cannot access private member declared in class 'std::function<_Fty>' D:\\Programme\\Development\\Visual Studio Ultimate 2012\\VC\\include\\list 1592 1 D-Tris 错误100错误C2248:'std :: function <_Fty> :: operator ==':无法访问类'std :: function <_Fty>'中声明的私有成员'D:\\ Program \\ Development \\ Visual Studio Ultimate 2012 \\ VC \\包括\\ list 1592 1 D-Tris

How can I remove an element from that list ? 如何从该列表中删除元素?

PS: CallbackBindings looks like this: PS:CallbackBindings如下所示:

static std::unordered_map<std::type_index, std::list<Callback>> callbackBindings;

You cannot compare std::function objects for equality. 您无法比较std::function对象的相等性。 You will have to remove them by other means, eg by index or iterator (which you have to store at the time of saving the callback), or by map key in an associative container. 您必须通过其他方式删除它们,例如通过索引或迭代器(您必须在保存回调时存储),或通过关联容器中的映射键。

(For example, imagine you inserted to callbacks that you specified locally as [](Event*){} . There is no mechanism or logic for telling whether any two such expressions should be considered "equal".) (例如,假设您插入到本地指定为[](Event*){}回调。没有机制或逻辑来判断是否应该将任何两个这样的表达式视为“相等”。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM