#include<iostream>
using namespace std;
#include"functional" //预定义函数对象的函数实现都写在这个库文件当中
#include"string"
#include<vector>
#include<list>
#include<algorithm>
#include"set"
/*总结*/
//1----->预定义函数对象基本概念:标准模板库STL提前定义了很多预定义函数对象,#include <functional> 必须包含。
//有关于plus<>预定义函数对象的正确使用 并且实现了算法与数据类型的分离 ----> 通过函数对象实现
void main21()
{
//关于参数个数,只需要追踪源码即可
plus<int> intAdd;
int a = 10;
int b = 21;
int c = intAdd(a, b);
cout << "C =" <<c<< endl;
plus<string> stringAdd;
string d = "hello";
string e = "CJLU";
string f = stringAdd(d, e);
cout << "f =" << f<<endl;
}
//有关sort中greater的使用
void main22()
{
vector<string> m_vec;
m_vec.push_back("ghello");
m_vec.push_back("dhello");
m_vec.push_back("khello");
m_vec.push_back("lhe
C++ 预定义函数对象以及函数适配器(一)
最新推荐文章于 2024-01-09 19:27:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)