大挪耗

c++可变函数和参数

#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号,我是一只傻傻鸟。
表白完成。


已发布

分类

可以收藏大挪耗一下。下载麻烦点城通网盘,站长保证下载速度,不会限速的,放心点就是了;分卷,安卓下载为txt:程序下载为url,不会下载参考不会下载。如果你想让本站活的久一点,请直接捐助

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注