标准参数与模板函数共同使用

来源:互联网 发布:做淘宝客能挣钱吗 编辑:程序博客网 时间:2024/05/12 17:34

测试代码:

#include<iostream>
using namespace std;

template<class X>void func(X a,int num)
{
 int i;
 for(i=0;i<num;i++)
  cout<<' ';
 cout<<a<<endl;
}

int main()
{
 func(3.14,1);
 func(10,3);
 func('A',4);
 func("hello",6);
 return 0;
}

测试结果:

 3.14
   10
    A
      hello
请按任意键继续. . .