template<class Fn,typename... Args>
void run(Fn fn,Args... args){
cout<<"before run"<<endl;
fn(args...);
cout<<"after run"<<endl;
}
int fun1(int a,int b){
cout<<"run fun1"<<endl;
cout<<a+b<<endl;
cout<<"fun1 end"<<endl;
}
int fun2(int a,int b,int c){
cout<<"run fun2"<<endl;
cout<<a+b+c<<endl;
cout<<"fun2 end"<<endl;
}
int main()
{
run(fun1,2,3);
run(fun2,32,34,34);
}
c++可变参数模版用法
最新推荐文章于 2024-09-27 11:26:03 发布