c++11std::function使用
#include <iostream>#include<functional>using namespace std;void fun(int a){cout << a << endl;}struct A{A& operator= (const A&){}void operator()(){cout << "void op
·
#include <iostream>
#include<functional>
using namespace std;
void fun(int a)
{
cout << a << endl;
}
struct A
{
A& operator= (const A&)
{
}
void operator()()
{
cout << "void operator()()" << endl;
}
static void abc(int a, int b)
{
cout << "void abc(int a, int b)" << endl;
}
void ab(int a, int b)
{
cout << "void abc(int a, int b)" << endl;
}
};
int main()
{
A a;
/*普通函数指针=静态成员函数指针(没有this指针)!=非静态成员函数指针*/
void (*p)(int, int) = &A::abc;
std::function<void(int)> f1 = fun;
std::function<void()> f2 = a;
std::function<void(int,int)> f3 = A::abc;
//std::function<void(int, int)> f4 = A::ab; 不可以,function不支持
return 0;
}
更多推荐
已为社区贡献4条内容
所有评论(0)