内建函数对象意义
概念:
STL内建了一些函数对象
分类:
- 算数仿函数
- 关系仿函数
- 逻辑仿函数
用法
这些仿函数所产生的的对象,用法和一般函数完全相同
使用内建函数对象,需要引入头文件# include
功能描述
- 实现四则运算
- 其中negate(取反)是一元运算,其他都是二元运算
仿函数原型
取反仿函数
#include <iostream>
#include <vector>
#include <algorithm> //算法头文件
#include <functional>
using namespace std;
//negate 一元仿函数 取反仿函数
void test1()
{
negate<int>n;
cout << n(50) << endl;
}
int main()
{
test1();
system("pause");
return 0;
}
加法仿函数
#include <iostream>
#include <vector>
#include <algorithm> //算法头文件
#include <functional>
using namespace std;
//plus 二元仿函数 加法
void test1()
{
plus<int>n;
cout << n(50,60) << endl;
}
int main()
{
test1();
system("pause");
return 0;
}