功能描述:
- 实现四则运算
- 其中negate是一元运算,其他都是二元运算
仿函数原型:
- template
T plus //加法仿函数 - template
T minus //减法仿函数 - template
T multiplies //乘法仿函数 - template
T divides //除法仿函数 - template
T modulus //取模仿函数 - template
T negate //取反仿函数
代码演示:
#include<iostream>using namespace std;#include<functional>//内建函数对象的头文件//内建仿函数 算数仿函数//negate 一元仿函数 (取反)void test01() {negate<int>a;cout << a(15) << endl;//-15}//plus 二元仿函数 (加法运算)void test02() {plus<int>a;cout << a(10, 5) << endl;}int main() {test01();test02();return 0;}
运行结果:
