Я знаю, как объявить int fn(double)
внутри std::function (std::function
). Я знаю, как написать указатель на член-функцию (typedef int (A::*MemFn)(double d);
). Но как мне написать указатель на член-функцию с помощью std::function?
Dummy code if you feel like compiling/testing
-edit- based on answers i think i'll just use the typedef and not bother with std::function
#include <cstdio>
#include <functional>
struct A{ int fn(double){ return 0; } };
int fn2(double){ return 0; }
typedef int (A::*MemFn)(double d);
typedef std::function<int(double)> MemFn2;
void Test(A*a, MemFn2 fn){
fn(1.2f);
}
void Test(A*a, MemFn fn){
(a->*fn)(1.2f);
}
int main(){
Test(new A, &A::fn);
Test(new A, &fn2);
}