函数调用运算符重载

#include <iostream>

class Add
{
public:
   int operator()(int a, int b)
   {
      std::cout << "operator()" << std::endl;

      return a + b;
   }
};

int main()
{
   using namespace std;

   Add add;
   int ret = add(10, 20);
   cout << ret << endl;

   /* 匿名对象 */
   cout << Add()(10, 20) << endl;

   return 0;
}
operator()
30
operator()
30
posted @ 2022-06-29 12:00  thomas_blog  阅读(19)  评论(0编辑  收藏  举报