【发布时间】:2011-08-11 15:27:16
【问题描述】:
我想尝试一下并在我们的动态库 API 包装器中统一一些样板代码。
基本上,我想做以下事情:
typedef bool (*MyFPtrT)(long id, std::string const& name);
typedef boost::function<bool (long id, std::string const& name)> MyFObjT;
...
...
MyFPtrT pDllFun = NULL;
long x = 42; string s = "Answer"; // API input, not hardcoded
MyFObjT f = boost::bind(pDllFun, x, s);
...
return Call(f);
...
template<FT>
bool Call(FT f) {
...
MyFPtrT pDllFun = (MyFunPtr)::GetProcAddress(...);
f.setFunctionPointerButLeaveBoundParameters(pDllFun); // <- how??
// Now call the correctly rigged up function object:
return f();
}
这可能吗? (使用 Boost 还是其他方式?)(C++03)
【问题讨论】:
-
我担心不可能......但让我们等待真正的答案:)
标签: c++ bind function-pointers boost-bind function-object