在visual studio 2013中编译此代码时出现编译错误(error C2064: term does not evaluate to function taking 0 arguments
)
#include <string>
#include <iostream>
#include <functional>
template<class F>
void foo(F& callback)
{
callback();
}
template<class F>
void bar(F& callback)
{
auto barCallback = std::bind([](F& callback)
{
callback();
std::cout << "world" << std::endl;
}, std::move(callback));
foo(barCallback);
}
int main()
{
std::string s("hello ");
auto f = std::bind([](std::string& s) { std::cout << s; }, std::move(s));
bar(f);
}
基本上,我想在这里实现的是将std::string
从main
移动到bar
然后转移到foo
(没有制作副本)