2

假设我有方法:

void foo(const std::string& s);

我可以创建 boost::function:

boost::function<void(const std::string&)> f = boost::bind(foo, temp);

f其中 temp 是在调用之前删除的 char* 。

4

2 回答 2

5

是的。Bind 无法知道 char* 可以保存在字符串中,或​​者它正在传递给字符串。为了避免这种情况,请使用:

boost::bind(foo, std::string(temp));

这样您的 temp 将作为字符串复制到活页夹中。

于 2011-02-01T13:42:51.320 回答
0

这是为你编译的吗?它应该是

boost::function<void()> f = boost::bind(foo, std::string(temp));
于 2011-02-11T17:37:14.307 回答