我正在尝试存储一个函数以稍后致电,这是片段。
这很好:
void RandomClass::aFunc( int param1, int param2, double param3, bool isQueued /*= false */ )
{
/* If some condition happened, store this func for later */
auto storeFunc = std::bind (&RandomClass::aFunc, this, param1, param2, param3, true);
CommandList.push( storeFunc );
/* Do random stuff */
}
但是,如果随机阶级是静态的,所以我相信我应该这样做:
void RandomClass::aFunc( int param1, int param2, double param3, bool isQueued /*= false */ )
{
/* If some condition happened, store this func for later */
auto storeFunc = std::bind (&RandomClass::aFunc, param1, param2, param3, true);
CommandList.push( storeFunc );
/* Do random stuff */
}
但这不起作用,我得到编译错误
错误c2668:'std :: tr1 :: bind':对重载功能的含糊不清
任何帮助。
静态成员函数指针的类型看起来像是指向非成员函数的指针:
auto storeFunc = std::bind ( (void(*)(WORD, WORD, double, bool))
&CSoundRouteHandlerApp::MakeRoute,
sourcePort, destPort, volume, true );
这是一个简化的示例:
struct Foo
{
void foo_nonstatic(int, int) {}
static int foo_static(int, int, int) { return 42;}
};
#include <functional>
int main()
{
auto f_nonstatic = std::bind((void(Foo::*)(int, int))&Foo::foo_nonstatic, Foo(), 1, 2);
auto f_static = std::bind((int(*)(int, int, int))&Foo::foo_static, 1, 2, 3);
}