#include <iostream.h>
template <______________>
void f(______________)
{
if(sizeof(T1)>sizeof(T2))
x=(T1)y;
else
y=(T2)x;
}
void main(){
double x=134.2;
int y=22;
f(x,y);
cout<&

完成程序题:请按空格顺序填写答案。

使下列程序的运行结果如下:
x=22,y=22


#include <iostream.h>
template <______________>
void f(______________)
{
if(sizeof(T1)>sizeof(T2))
x=(T1)y;
else
y=(T2)x;
}
void main(){
double x=134.2;
int y=22;
f(x,y);
cout<<″x=″<<x<<″,y=″<<y;
}


【正确答案】:

第1空:CLASS T1,CLASS T2
第2空:T1 &X,T2 &Y


【题目解析】:

声明类模板的一般格式如下:


类模板参数根据题目中使用设置为class T1,class T2,根据函数中使用设置引用T1 &x,T2 &y


Top