填空题
使用VC6打开考生文件夹下的工程test27_1,此工程包含一个源程序文件test27_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为;
100
源程序文件test27_1.cpp清单如下:
#include <iostream.h>
template <class T>
class pair
{
T valuel, value2;
public:
pair (T first, T second)
{valuel=first; value2=second;}
/***************** found *****************/
char getmax ();
};
/***************** found *****************/
T pair<T>::getmax ()
{
T retval;
/***************** found *****************/
retval = valuel>value2 value1 : value2;
return retval;
}
void main ()
{
pair <int> myobject (100, 75);
cout << myobject.getmax()<<end1;
}
【参考答案】
(1)错误:char getmax(); 正确:T getmax(); (2)错误:缺少模板的声明 正确:templat......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)