Use std::bind
.
auto func = std::bind(&Toto::foo, ptr, std::placeholders::_1);
here, func
will be deduced to type, that was returned from std::bind
or if you don't like auto
you can use (and you want to use std::function
)
std::function<void(int)> func = std::bind(&Toto::foo,
ptr, std::placeholders::_1);
Here std::function
will be constructed from result of std::bind
.
ptr
will be copied to some object returned from std::bind
, however you can use std::ref
/std::cref
if you don't want copies.