这段时间继续学习std::bind的用法,
继续上篇的学习,结合查找资料
更加深入的研究了一下,结合std::function,以及lambda表达式
以下是例子
#include <iostream>
#include <functional>
void f(int a, int b, int c)
{
std::cout << "a=" << a << " " << "b=" << b << " " << "c=" << c << std::endl;
}
int ret4()
{
std::cout << "ret4() calld" << std::endl;
return 4;
}
void columns(int x)
{
std::cout << "-----------------example:" << x << "-----------------" << std::endl;
}
class Foo
{
public:
void f(int a, int b, int c)
{
std::cout << "Foo::f():" << "a=" << a << " " << "b=" << b << " " << "c=" << c << std::endl;
}
int x = 1;
int _a{
100 };
};
//C++11 特性trailing return types decltype是推倒类型,推导返回值类型
template <typename T1, typename T2>
auto add(const T1& t1, const T2& t2) -> decltype(t1 + t2)
{
return t1 + t2;
}
//C++14 注意与上边的对比,不用显式写出推导返回值
template <typename T1, typename T2>
auto add2(const T1& t1, const T2& t2)
{
return t1 + t2;
}
int main()
{
columns(1);
//1.绑定最普通的函数