#include<iostream>
using namespace std;
#include<string>
class Myprint
{
public:
void operator()(string test)
{
cout << test << endl;
}
};
class myadd
{
public:
int operator()(int a, int b)
{
return a+b;
}
};
void myprint2(string test)
{
cout << test << endl;
}
void test01()
{
Myprint myprint;
myprint("hello world");
myprint2("hello tingting");
myadd add;
int b = add(10,20);
cout << b;
cout << myadd()(10,50) << endl; //nimingduixiang
}
int main()
{
test01();
}
C++ 仿函数
最新推荐文章于 2024-08-15 05:02:54 发布
本文详细探讨了C++中的仿函数(Functors),解释了它们如何作为对象实现函数行为,以及在泛型编程和STL中的应用,包括自定义比较函数、适配器和类型转换等关键用例。
摘要由CSDN通过智能技术生成