#include "iostream"
#include "thread"
#include <functional>
using namespace::std;
void show0(){//普通函数
cout<<"亲爱的,我是一只傻傻鸟。\n";
}
void show1(const string&message)
{//普通函数
cout<<"亲爱的,"<<message<<endl;
}
struct CC//类中有成员函数。
{
void show2(int bh,const string& message)
{
cout<<"亲爱的"<<bh<<"号,"<<message<<endl;
}
};
template<typename Fn,typename...Args>
auto show(Fn fn,Args...args)-> decltype(bind(fn,args...))
{
cout<<"表白前的准备工作...\n";
auto f=bind(forward<Fn>(fn),forward<Args>(args)...);
f();
cout<<"表白完成。\n";
return f;
};
int main()
{
thread tt();
thread t1(show0);
thread t2(show1,"我是一只傻傻鸟。");
CC cc;
thread t3(&CC::show2,&cc,3,"我是一只傻傻鸟。");
t1.join();
t2.join();
t3.join();
show(show0);
show(show1,"我是一只傻傻鸟。");
show(&CC::show2,&cc,3,"我是一只傻傻鸟。");
}
亲爱的,我是一只傻傻鸟。
亲爱的,我是一只傻傻鸟。
亲爱的3号,我是一只傻傻鸟。
表白前的准备工作…
亲爱的,我是一只傻傻鸟。
表白完成。
表白前的准备工作…
亲爱的,我是一只傻傻鸟。
表白完成。
表白前的准备工作…
亲爱的3号,我是一只傻傻鸟。
表白完成。
发表回复