1 //函数调用运算符重载
2
3 #include <iostream>
4 #include <string>
5 using namespace std;
6
7 //函数调用运算符重载
8
9 class MyPrint
10 {
11 public:
12
13 //重载函数调用运算符
14 void operator()(string test)
15 {
16 cout << test << endl;
17 }
18
19 };
20
21 void MyPrint02(string test)
22 {
23 cout << test << endl;
24 }
25
26 void test01()
27 {
28 MyPrint myprint;
29
30 myprint("biubiubi");//由于使用起来像函数调用 因此称为 仿函数
31
32 MyPrint02("nssidissd");
33 }
34 //仿函数非常灵活 没有固定写法
35 //加法类
36
37 class MyAdd
38 {
39
40 public:
41 int operator()(int num1, int num2)
42 {
43 return num1 + num2;
44 }
45 };
46
47
48 void test02()
49 {
50 MyAdd myadd;
51 int ret = myadd(100, 100);
52 cout << "ret = " << ret << endl;
53
54 //匿名函数对象 当前行执行完了 立即被释放
55 cout << MyAdd()(100, 100) << endl;
56 }
57 int main()
58 {
59 test01();
60 test02();
61 }

最新文章

  1. Jenkins FTP 上传
  2. 死锁及oracle死锁--转载
  3. Linux网络
  4. MessageFormat类别:快速格式化字符串
  5. JVM-6.即时编译器
  6. 书籍--嵌入式Linux驱动开发
  7. Java 枚举(enum) 详解7种常见的用法
  8. ajax请求导致status为canceled(无任何回调数据)的原因
  9. mysql,utf8,utf8mb4
  10. 一文读懂什么是Java中的自动拆装箱
  11. 20181016-4 Alpha阶段第1周/共2周 Scrum立会报告+燃尽图 04
  12. ffmpeg源码分析五:ffmpeg调用x264编码器的过程分析 (转5)
  13. ConstraintLayout导读
  14. python编码问题 与 代码换行问题
  15. 没有局域网环境,全是公网IP可以做LVS吗,该如何做了!请大家赐教!
  16. delphi小知识 点(if条件符,to_date)
  17. hdu1316
  18. Trie树,又称单词查找树、字典
  19. redis主从+哨兵模式
  20. perl中foreach(二)

热门文章

  1. 【原创】Ingress-Nginx-Controller的Metrics监控源码改造简析
  2. 13、windows下卸载oracle
  3. 前端 | Vue 路由返回恢复页面状态
  4. shell 调用其他shell脚本中的变量、函数
  5. php漏洞 strcmp漏洞
  6. Leetcode No.35 Search Insert Position(c++实现)
  7. ESP32的Flash加密知识
  8. 深入浅出 Jest 框架的实现原理
  9. c语言字符串存储方式
  10. Leetcode No.14 Longest Common Prefix最长公共前缀(c++实现)