文档里有这样的一个范例,我在程序里运行时老是报错。大神看一下,怎么改。#include <iostream>using namespace std;template <class T> class pair{ T value1, value2; public: pair(T first, T second) { value1 =first; value2=second; } T getmax(); };template <class T>T pair::getmax (){ T retval; retval = value1>value2? value1:value2; return retval;};int main() { pair myobject(100,75); cout<<myobject.getmax(); return 0;}运行时提示:
#include <iostream>
using namespace std;
template <class T> class pair
{
T value1, value2;
public:
pair(T first, T second)
{
value1 =first;
value2=second;
}
T getmax();
};
template <class T>T pair::getmax ()
{
T retval;
retval = value1>value2? value1:value2;
return retval;
};
int main()
{
pair myobject(100,75);
cout<<myobject.getmax();
return 0;
}
相关分类