#include<iostream>
#include<functional> //函数绑定器
using namespace std;
using namespace std::placeholders;
template<class T>
void show(T t)
{
cout << t << endl;
}
struct MyStruct
{
template<class T>
void show(T t)
{
cout << t << endl;
}
template<class T>
void showIt(T t1,T t2)
{
cout << t1<<" "<<t2 << endl;
}
void go()
{
show(123); //推理类型
}
};
void main09()
{
//void(*p)() = show;
void(*px)(int a) = show<int>; //必须指定类型。
px(22);
MyStruct ms;
ms.go();
ms.show(456);
ms.show("abc"); //推理类型
ms.show('A'); //推理类型
ms.show<int>('A'); //指定类型
//函数绑定器 show<int> 要指定类型 ,_1:表示有一个参数
auto fun = bind(&MyStruct::show<int>,&ms, _1);
fun(321);
//_1,_2:表示有二个参数
auto fun1 = bind(&MyStruct::showIt<int>, &ms,_1,_2);
fun1(11, 22);
// 1:表示第一个参数默认值为 1 ,_1
auto fun2 = bind(&MyStruct::showIt<int>, &ms, 11,_1);
fun2(33);
//fun2(66, 99); //使用了默认参数后就不能可以这样调用。
//88,99:二个默认参数,
auto fun3 = bind(&MyStruct::showIt<int>, &ms, 88,99 );
fun3();
cin.get();
}