我想尝试一些东西并在我们的动态库 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)