类的模板
来源:互联网 发布:尼泊尔淘宝 编辑:程序博客网 时间:2024/06/05 07:21
声明一个类的模板的时候,在定义之前增加一行
template
**#include <iostream>using namespace std;template <typename 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> cmpl(3,7); cout<<cmpl.max()<<"is the Maximum of two integer numbers."<<endl; cout<<cmpl.min()<<"is the Minimum of two integer numbers."<<endl; Compare <float> cmp2(3.2323,7.658); cout<<cmpl.max()<<"is the Maximum of two integer numbers."<<endl; cout<<cmpl.min()<<"is the Minimum of two integer numbers."<<endl; Compare <char> cmp3('A','G'); cout<<cmpl.max()<<"is the Maximum of two integer numbers."<<endl; cout<<cmpl.min()<<"is the Minimum of two integer numbers."<<endl; return 0;} **
**/home/andrew/文档/Clion/untitled5/cmake-build-debug/untitled57is the Maximum of two integer numbers.3is the Minimum of two integer numbers.7is the Maximum of two integer numbers.3is the Minimum of two integer numbers.7is the Maximum of two integer numbers.3is the Minimum of two integer numbers.Process finished with exit code 0**
0 0
- 模板的模板类
- 模板函数,函数模板,模板类,类模板的区别
- 模板的概念 ---模板分两类:函数模板和类模板
- 模板的概念 ---模板分两类:函数模板和类模板
- 模板的概念 ---模板分两类:函数模板和类模板
- 类模板和模板类的区别
- 类模板与模板类的概念
- 类模板与模板类的概念
- c++模板类的模板类友元示例
- 函数模板与类模板的区别
- 模板类的友元模板函数
- C++模板类/模板函数的BUG
- 函数模板与类模板的区别
- 函数模板与类模板的区别
- 函数模板与类模板的区别
- 函数模板与类模板的区别
- 函数模板与类模板的区别
- 函数模板和类模板的使用
- 欢迎使用CSDN-markdown编辑器
- 本地调用, “本地调用”和远程调用!
- c++可变参数模板
- VS编译问题
- 从百度统计看到的一些有意思的事情
- 类的模板
- 畅通工程 并查集
- 数据回显
- GeoHash核心原理解析
- gettid和pthread_self区别
- struct elevator_queue
- 一个今天遇到的vs编译器怪现象
- HINSTANCE和HWND的区别
- "finally block does not complete normally"警告解决