【发布时间】:2010-10-14 09:35:01
【问题描述】:
我有一些(库API,所以我不能更改函数原型)函数,编写方式如下:
void FreeContext(Context c);
现在,在我执行的某个时刻,我有Context* local_context; 变量,这也是不可更改的主题。
我希望将boost::bind 与FreeContext 函数一起使用,但我需要从局部变量Context* 中检索Context。
如果我按以下方式编写代码,编译器会说这是“非法间接”:
boost::bind(::FreeContext, *_1);
我设法通过以下方式解决了这个问题:
template <typename T> T retranslate_parameter(T* t) {
return *t;
}
boost::bind(::FreeContext,
boost::bind(retranslate_parameter<Context>, _1));
但这个解决方案对我来说似乎并不是很好。关于如何使用*_1 之类的解决此问题的任何想法。 也许写一个小的 lambda 函数?
【问题讨论】:
标签: c++ pointers function boost boost-bind