相关疑难解决方法(0)

使用std :: tr1 :: function(或boost :: function)创建多播事件

我正在尝试使用TR1中的功能创建类似C#的多播委托和事件.或者Boost,因为boost :: function(大部分)与std :: tr1 :: function相同.作为概念证明,我试过这个:

template<typename T1>
class Event
{
private:
 typedef std::tr1::function<void (T1)> action;
 std::list<action> callbacks;

public:

 inline void operator += (action func)
 {
  callbacks.push_back(func);
 }

 inline void operator -= (action func)
 {
  callbacks.remove(func);
 }

 void operator ()(T1 arg1)
 {
  for(std::list<action>::iterator iter = callbacks.begin();
   iter != callbacks.end(); iter++)
  {
   (*iter)(arg1);
  }
 }
};
Run Code Online (Sandbox Code Playgroud)

哪个有用,有点像.这条线callbacks.remove(func)没有.当我编译它时,我收到以下错误:

error C2451: conditional expression of type 'void' is illegal
Run Code Online (Sandbox Code Playgroud)

这是由函数中的list标题的第1194行引起的remove.是什么造成的?

c++ delegates boost stl tr1

3
推荐指数
1
解决办法
2202
查看次数

标签 统计

boost ×1

c++ ×1

delegates ×1

stl ×1

tr1 ×1