作业帮 > 综合 > 作业

C++中如何在类模板外定义函数

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/05/09 22:30:07
C++中如何在类模板外定义函数
#include
using namespace std;
template
class Compare
{ private:
numtype x;
numtype y;
public:
Compare(numtype a,numtype b)
{
x=a;
y=b;
}
numtype max()
{
return (x>y)?x:y;
}
numtype min()
{
return (x
C++中如何在类模板外定义函数
#include
using namespace std;
template
class Compare
{
private:
numtype x;
numtype y;
public:
Compare(numtype,numtype);
numtype max();
numtype min();
};
// 在类模板外面定义其成员函数:
template
Compare::Compare(numtype a,numtype b){
x = a;
y = b;
}
template
numtype Compare::max(){
return (x>y)? x:y;
}
template
numtype Compare::min(){
return (x