【发布时间】:2016-01-18 20:20:00
【问题描述】:
我正在尝试在我的 lambda 中使用 std::bind:
#include <functional>
#include <iostream>
#include <string>
struct Foo {
Foo() {}
void func(std::string input)
{
std::cout << input << '\n';
}
void bind()
{
std::cout << "bind attempt" << '\n';
auto f_sayHello = [this](std::string input) {std::bind(&Foo::func, this, input);};
f_sayHello("say hello");
}
};
int main()
{
Foo foo;
foo.bind();
}
当我运行这段代码时,我期望看到以下输出
bind attempt
say hello
但我只看到“绑定尝试”。我很确定 lambda 有一些我不明白的地方。
【问题讨论】:
-
std::bind(&Foo::func, this, input)();? -
@PiotrSkotnicki 哇,快速有效的答案。谢谢
标签: c++ c++11 lambda std stdbind