0
点赞
收藏
分享

微信扫一扫

std::bind

耳一文 2023-03-16 阅读 74


源码

template <class F,class...Args>

bind(F&& f , Args&&...args);

例子

void func(int a,int b)
{
std::cout<<a+b<<endl;
}
struct Foo
{
void p(int a,int b){
cout<<"fo"<<endl;
}
}
auto f=std::bind(func,_1,_2);f(1,3)=4
//auto f=std::bind(func,_1,_1); f(1,3)=2
// auto f=std::bind(func,1,2); f(1,3)=3
Foo fo;
//auto f=std::bind(&Foo::p,fo,_1,_2);//ivoke a member function fo好像&fo fo都可以
using namespace std::placeholder;这个命名空间不能忘了。
f(1,2);



举报

相关推荐

0 条评论