首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于类模板有关问题?难到潭浩强的书又出错了

2012-03-09 
关于类模板问题?难到潭浩强的书又出错了?跟书的代码一样,编译就是报错。。。。求解#includeiostreamusing na

关于类模板问题?难到潭浩强的书又出错了?
跟书的代码一样,编译就是报错。。。。求解

#include<iostream>
using namespace std;
template<class numtype>
class Compare
{
public:
Compare(numtype a,numtype b)
{x=a;y=b;}
numtype max()
{
return(x>y)?x:y;
}
numtype min()
{return (x<y)?x:y;}
private:
numtype x,y;
};




int main()
{
Compare<int>cmp1{4,7};
cout<<cmp1.max()<<"is the Maximum of two integer numbers."<<endl;
cout<<cmp1.min()<<"is the minimum of two integer numbers."<<endl<<endl;
  Compare<float>cmp2{45.78,93.6};
cout<<cmp2.max()<<"is the Maximum of two float numbers."<<endl;
cout<<cmp2.min()<<"is the Minimum of two float numbers."<<endl<<endl;
return 0;
}

[解决办法]
Compare<int>cmp1(4,7);
Compare<float>cmp2(45.78,93.6);
[解决办法]
LZ眼花了吧,呵呵,不是大括号
[解决办法]
Compare<int>cmp1{4,7};
不能用大括号

热点排行