I have a function:
std::function<void(sp_session*)> test(void(MainWindow::*handler)())
{
return ...;
}
I would like to replace handler’s type with the equivalent std::mem_fn type.
What is the type?
I tried this:
std::function<void(sp_session*)> test(std::mem_fn<void(), MainWindow> handler)
{
return ...;
}
But VC++ 2010 spits out these errors:
error C2146: syntax error : missing ')' before identifier 'handler'
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)
So I am not sure what I did wrong.
std::mem_fnis not the type you are looking for.The type you need is
std::functionthat takes the instance as argument:It can bind to member function and is just used with the instance as first parameter.
If in the original function you would do:
In the new function you do: