我想从另一个调用GetProcAddress的函数给出的FARPROC地址返回一个函数实例。提出了一个有趣的问题。这里的功能:函数指针到多个参数C++ 11 std :: function:模板GetProcAddress
template<class FT>
std::function<FT> to_function(FARPROC address) {
return address;
}
后来我想创建一个没有输入功能没有任何问题:
auto try1 = to_function<int()>(addr1);
然而,当函数需要一个输入,在Visual C++ 11的编译器爆炸:
auto try2 = to_function<int(int)>(addr2);
它正确地返回:
错误C2197:'int(__stdcall *)(vo id)':调用的参数太多
所讨论的类型与FARPROC相当,即GetProcAddress返回的内容,与函数的参数列表无关。
为了说明问题,我的问题是如何通过将FARPROC强制转换为std :: function的适当类型来解决此问题?提前欢呼。
“FARPROC”究竟是什么? –
它只是一个函数指针int(__stdcall *)(void) – austere
我认为你正在寻找['std :: bind'](http://en.cppreference.com/w/cpp/utility/functional/bind) 。 –