题库 题库

【简答题】

改错题
使用VC6打开考生文件夹下的工程kt12_1,此工程包含一个源程序文件kt12_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:
100
源程序文件kt12_1.cpp清单如下:
#include
template
classpair
{ Tvalue1,value2;
public:
pair(Tfirst,Tsecond)
{value1=first;value2=second;}
/*****************found*****************/
chargetmax(); };
/*****************found*****************/
Tpair::getmax()
{ Tretval;
/*****************found*****************/
retval=value1>value2??value1:value2;
returnretval; }
voidmain()
{ pairmyobject(100,75);
cout<<MYOBJECT.GETMAX()<<>

参考答案

(1)将char getmax ();改为:T getmax ();
(2)缺少模板的声明,应改为:template
(3)将retval = value1>value2?? value1 : value2;
改为:retval = value1>value2? value1 : value2;

相关试题