码迷,mamicode.com
首页 > 其他好文 > 详细

自考新教材-p352_1

时间:2020-02-06 01:20:55      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:cin   name   return   img   image   inf   ios   ace   com   

源程序:

#include <iostream>
using namespace std;
template <class T>

class max
{
private:
T x, y;
public:
max(T a, T b)
{
x = a;
y = b;
}
T compare()
{
return (x > y) ? x : y;
}
};

//template <class T>
int main()
{
//T xx, yy;
//cout << "请输入两个数:";
//cin >> xx >> yy;
max <int>m1(2, 4);
cout << m1.compare() << endl;
max <double>m2(3.5, 1.7);
cout << m2.compare() << endl;
max <char>m3(‘m‘, ‘p‘);
cout << m3.compare() << endl;
system("pause");
return 1;
}

运行结果:

技术图片

 

自考新教材-p352_1

标签:cin   name   return   img   image   inf   ios   ace   com   

原文地址:https://www.cnblogs.com/duanqibo/p/12267301.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!