126-函数调用运算符重载

#include
using namespace std;
#include
//函数调用运算符重载
class MyPrint{

public:
	//重载函数调用运算符
	void operator()(string test) 
	{
		cout << test << endl;
	}
};
void test01() {
	MyPrint myprint;

	myprint("hello world");//像不像
	
}
//仿函数非常灵活,像山里灵活的狗
class MyAdd {
public:
	int operator()(int num1,int num2)
	{
		return num1 + num2;
	}
};
void test02() {
	MyAdd myadd;
	int result=myadd(100, 100);
	cout << result << endl;
	//创建匿名函数对象---更简单;
	cout << MyAdd()(100, 100);
}
int main() { 
	test01();
	test02();
}

void dogofAyaka ()(string dog)

{

 cout<<"loveyou!"<

}

你可能感兴趣的:(算法)