首页 > 其他 > 详细

可变参数函数模板

时间:2014-09-02 00:03:23      阅读:248      评论:0      收藏:0      [点我收藏+]

16.53 编写你自己版本的print函数,并打印一个、两个及五个实参来测试它,要打印的每个实参都应有不同的类型。

#include<iostream>
#include<string>
using namespace std;

template <typename T>
ostream& print(ostream &os,const T &t)
{
    os<<t;
    return os;
}

template <typename T,typename ... Args>
ostream& print(ostream &os,const T &t,const Args&...rest)
{
    os<<t<<" , ";
    return print(os,rest...);
}

int main()
{
    print(cout,1,3.14,"hello");
}

 

可变参数函数模板

原文:http://www.cnblogs.com/wuchanming/p/3950482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!