126类和对象_ 运算符重载_仿函数调用
 学习内容
         仿函数调用
结果

代码
#include<iostream>
using namespace std;//cout 在这里,没有它会报错
#include<string>
//126类和对象_ 运算符重载_仿函数调用
//学习内容
//仿函数调用
class MyPrint
{
public:
	/// <summary>
	/// 仿函数调用
	/// </summary>
	/// <param name="str"></param>
	void operator()(string str)
	{
		cout << str << endl;
	}
};
class MyAdd
{
public:
	/// <summary>
	/// 仿函数调用
	/// </summary>
	/// <param name="str"></param>
	int operator()(int num1 , int num2)
	{
		return num1 + num2;
	}
};
void test03()
{
	MyPrint myprint;
	//看起来像一个函数的调用
	myprint("调用仿函数调用");
	MyAdd myadd;
	
	cout << "myadd 结果:" << myadd(10, 20) << endl;
	//匿名函数调用
	cout << "匿名函数调用 myadd 结果:" << MyAdd()(30, 20) << endl;
}
int main()
{
	test03();
	system("pause");
}
 
                


















