1:函数调用运算符()也可以重载。
    2:由于重载后使用的方式非常像函数的调用,因此成为仿函数。//仿函数也就是重载的小括号。
    3:仿函数没有固定写法,非常灵活。

    示例:

    1. #include<iostream>
    2. #include<string>
    3. using namespace std;
    4. class Person
    5. {
    6. public:
    7. void operator()(string s)
    8. {
    9. cout<<s<<endl;
    10. }
    11. };
    12. class Print
    13. {
    14. public:
    15. int operator()(int num1,int num2)
    16. {
    17. return num1+num2;
    18. }
    19. };
    20. void show()
    21. {
    22. Person p;
    23. p("iu");
    24. Print p0;
    25. int result;
    26. result=p0(100,100);
    27. cout<<result<<endl;
    28. return ;
    29. }
    30. int main()
    31. {
    32. show();
    33. return 0;
    34. }

    网址:https://www.bilibili.com/video/BV1et411b73Z?p=126

    添加的注释:析构函数不返回任何值,没有函数类型,也没有函数参数,因此它不能被重载。 构造函数可能有多个,但析构函数只能有一个,就像人来到人世间,可能出生的环境家庭不同(重载构造函数),但最终都会死亡(析构函数)。