急!急!在线等!高手帮看一下本人在类外定义类模版的成员函数哪里不对?

C++语言 码拜 8年前 (2016-01-29) 678次浏览
#include <iostream>
using namespace std;
template<class numtype>//类型参数名
class Compare//类模板
{
public:
Compare(numtype a,numtype b):aa(a),bb(b){};//构造函数
numtype max(); numtype min();
/*
numtype max()
{
return (aa>bb)?aa:bb;
}
numtype min()
{
return (aa<bb)?aa:bb;
}*/
private:
numtype aa,bb;
};
int main()
{
Compare<int> c(3,7);//定义类的对象*****注意定义的形式
Compare<float> d(1.2,1.0);//同上
cout <<c.max()<<” “<<c.min()<< endl;
cout <<d.max()<<” “<<d.min()<< endl;
return 0;
}
template<class numtype>
numtype Comepare<numtype>::max()
{
return (aa>bb)?aa:bb;
}
template<class numtype>
numtype Comepare<numtype>::min()
{
return (aa<bb)?aa:bb;
}
解决方案:20分
template<class numtype>//类型参数名
class Compare//类模板
template<class numtype>
numtype Comepare<numtype>::max()
类型名不同,这里出现笔误了
改正就好

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明急!急!在线等!高手帮看一下本人在类外定义类模版的成员函数哪里不对?
喜欢 (0)
[1034331897@qq.com]
分享 (0)