习题 9.12 将例9.14改写为在类模板外定义各成员函数
发布时间
阅读量:
阅读量
习题 9.12 要求将例9.14中的内容进行调整,使各类模板的成员函数在类模板外部进行定义。
代码:
#include<iostream>
using namespace std;
template <class numtype>
class Compare
{
public:
Compare(numtype a, numtype b)
{
x = a; y = b;
}
numtype max();
numtype min();
private:
numtype x, y;
};
template <class numtype>
numtype Compare<numtype>::max()
{
return (x > y) ? x : y;
}
template <class numtype>
numtype Compare<numtype>::min()
{
return (x < y) ? x : y;
全部评论 (0)
还没有任何评论哟~
