(给CPP开发者加星标,提升C/C++技能)
来源:但行技术 https://blog.csdn.net/weixin_43333380/article/details/82935291
【导读】:
可将std::bind函数看作一个通用的函数适配器,它接受一个可调用对象,生成一个新的可调用对象来“适应”原对象的参数列表。
std::bind将可调用对象与其参数一起进行绑定,绑定后的结果可以使用std::function保存。
以下是正文
一 使用场景
先将可调用的对象保存起来,在需要的时候再调用,是一种延迟计算的思想。不论是普通函数、函数对象、还是成员函数,成员变量都可以绑定,其中成员函数都可以绑定是相当灵活的。
二 头文件
定义于头文件
#include
三 bind原型
a.)
template< class F, class... Args >/*unspecified*/ bind( F&& f, Args&&... args );
b.)
template< class R, class F, class... Args >/*unspecified*/ bind( F&& f, Args&&... args );
四 绑定普通函数
头文件
#include #include
定义函数
int TestFunc(int a, char c, float f){
std::cout << a << std::endl; std::cout <&