HUH函数
函数名:display 功能:显示输出函数 用法:void display(); 程序示例: 程序例: #include<iostream.h> template <class k1, class k2> void display(k1 x, k2 y); void main() { char c='h',str[]="ok2002"; int n=100; float x=5.5; double z=1.23456; //两个参数类型相同 display(c, char(c+2)); //h j display(x,2*x); //5.5 11 display(n, 2*n); //100 200 display(str, str); //ok2002 ok2002 display(z, 2*z); //1.23456 2.46912 //两个参数类型不同 display(c, str); //h ok2002 display(str,2*x); //ok2002 11 display(str, c); //ok2002 h display(n, str); //100 ok2002 display(z, n); //1.23456 100 } //定义名为display的函数模板 template <class k1, class k2> void display(k1 x, k2 y) { cout<<x<<"\t"<<y<<endl; }
侃侃尔雅
功能:显示输出函数用法:void display();程序例:#include<iostream.h>template <class k1, class k2>void display(k1 x, k2 y);void main(){char c='h',str[]="ok2002";int n=100;float x=5.5;double z=1.23456;//两个参数类型相同display(c, char(c+2)); //h jdisplay(x,2*x); //5.5 11display(n, 2*n); //100 200display(str, str); //ok2002 ok2002display(z, 2*z); //1.23456 2.46912//两个参数类型不同display(c, str); //h ok2002display(str,2*x); //ok2002 11display(str, c); //ok2002 hdisplay(n, str); //100 ok2002display(z, n); //1.23456 100}//定义名为display的函数模板template <class k1, class k2>void display(k1 x, k2 y){cout<<x<<"\t"<<y<<endl;}