小编nyk*_*kac的帖子

C++ 11 Lambda问题

任何想法为什么以下代码段错误?

class foo代表任何阶级.这种接缝就像提供一个公平的界面一样好.

#include <iostream>
#include <functional>

class foo
{
public:
  foo()
  {
    val = 42;  
  };

  void bar(std::function<int(foo*)> f)
  {
    this->_bar = std::bind(f, this);
  }
  std::function<int()> _bar;
  int val;
};

int main(void)
{
  foo *foobar;
  foobar->bar([](foo *self)->int{return self->val;});

  std::cout << foobar->_bar();
}
Run Code Online (Sandbox Code Playgroud)

c++ lambda c++11

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

标签 统计

c++ ×1

c++11 ×1

lambda ×1