将例3.14改写为在类模版外定义各成员函数(第三章第十二题)
来源:互联网 发布:网络电话会议软件 编辑:程序博客网 时间:2024/06/04 17:53
#include <iostream>using namespace std;template<class numtype>class Compare{public:Compare(numtype a,numtype b);numtype max();numtype min();private:numtype x,y;};template <class numtype>Compare<numtype>::Compare(numtype a,numtype b){x=a;y=b;}template <class numtype>numtype Compare<numtype>::max(){return (x>y)?x:y;}template <class numtype>numtype Compare<numtype>::min(){return (x<y)?x:y;}int main(){Compare<int> cmp1(3,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;Compare<char> cmp3('a','A');cout<<cmp3.max()<<" is the Maximum of two characters."<<endl;cout<<cmp3.min()<<" is the Minimum of two characters."<<endl;return 0;}
0 0
- 将例3.14改写为在类模版外定义各成员函数(第三章第十二题)
- 2,改写本章例2.1程序,要求: (1)将数据成员改为私有; (2)将输入和输出的功能改为由成员函数实现; (3)在类体内定义成员函数;
- 5,将本章的例2.4改写为一个多文件的程序: (1)将类定义放在头文件arraymax.h中; (2)将成员函数定义放在源文件arraymax.cpp中; (3)主函数放在源文件filel.cpp中。
- 模版类的成员函数定义问题
- C++类的成员函数(在类外定义成员函数、inline成员函数)
- C++类的成员函数(在类外定义成员函数、inline成员函数)
- C++类的成员函数(在类外定义成员函数、inline成员函数)
- C++类的成员函数(在类外定义成员函数、inline成员函数)
- C++类的成员函数(在类外定义成员函数、inline成员函数)
- 在类体内申明成员函数(第二章第三题)
- C++定义隐式转换函数,将类转换为内部的一个成员变量
- 将重载运算符定义为成员函数还是普通的非成员函数
- C++:成员函数实现在类定义中与在类定义外的区别
- 第一周阅读程序(1) 成员函数在类内声明,类外定义
- 3,在第2题的基础上进行如下操作:在类体内声明成员函数,而在类外定义成员函数
- 将例3.13中程序中的display函数不放在Time类中(第三章第10题)
- my_mem_fun_ref将类成员函数转换为仿函数
- 第三章第十二题
- java.util.Date.getTime()方法实例
- DC,CDC,HDC,CClientDC
- 3-7(2)
- C#窗体不能拖大拖小 C#窗体不出现在任务栏中
- Linux下查看磁盘使用率及文件和文件夹大小
- 将例3.14改写为在类模版外定义各成员函数(第三章第十二题)
- POJ1035 Spell checker 字符串模拟
- MVC4.0网站发布和部署到IIS7.0上的方法
- apple官方文档翻译:使用NSURLSession(二)
- Hbase 入门简介
- oracle 巡检脚本
- JS判断是否是数组Array
- 解题报告 之 ZOJ2760 How Many Shortest Path
- 11gR2单机通过RMAN恢复到RAC