函数对象的学习
来源:互联网 发布:两台光谱仪数据不一样 编辑:程序博客网 时间:2024/05/16 01:04
<span style="font-size:24px;">#include<iostream> #include<vector> #include<string> #include<algorithm> #include<numeric> using namespace std; class MyMax { public: bool operator()(int a1,int a2) { if((a1%10)<(a2%10)) return 1; else return 0; } }; bool MyLess(int a1,int a2) { if((a1%10)<(a2%10)) return 0; else return 1; } template<class T2,class T3> T2 Mycompare(T2 first,T2 last,T3 t3) { T2 max=first; for(;first!=last;first++) { if(t3(*max,*first)) { *max=*first; } } return max; } int main() { int a[]={35,7,13,19,61}; cout<<*Mycompare(a,a+5,MyMax())<<endl; cout<<*Mycompare(a,a+5,MyLess)<<endl; system("pause"); return 0; } </span>
基于函数对象的C++编程
利用编写Mycompare类模板,以函数MyLess和对象MyMax为一个对象参数传入T2、T3中,进行不同种类的排序,选出符合各自逻辑的最值。
其中:Myless选出的是个位数最大的数字;
MyMax选出的是个位数最小的数字;
0 0
- 函数对象的学习
- javascript学习 - js的Date对象函数
- java面向对象构造函数的学习
- JS学习笔记-函数对象的方法
- STL--函数对象学习
- Boost学习------函数对象
- 面向对象的程序设计学习笔记-默认的构造函数
- js笔记之函数的arguments对象的学习
- 《Javascript语言精粹》的学习(一).对象和函数
- [ADO学习笔记] Connection对象的函数与方法
- [ADO学习笔记] RecordSet对象的函数与方法
- [ADO学习笔记] Recordset 对象中的updateBatch函数的使用方法
- JavaScript学习——Math对象定义的函数
- C++常对象、常成员函数的学习
- 【学习-水滴石穿】 JavaScript用arguments对象访问函数的参数
- 初探swift语言的学习笔记四(类对象,函数)
- swift语言的学习笔记四(类对象,函数)
- 初探swift语言的学习笔记四(类对象,函数)
- HTTP
- C++双冒号::的作用
- php面试需要掌握的基础题目锦集
- kissy reset css
- android之XmlResourceParser类使用实例
- 函数对象的学习
- OpenGL ES2.0 生成Mipmap纹理
- WiFi战场,谁主沉浮
- (一)安装Linux 服务器
- ThreadLocal
- eclipse的console信息太多,看不到之前的信息
- start-stop-daemon
- 深入浅出URL编码
- java新特性——读写锁ReadWriteLock