html5国内网站,食品网站的建设背景,什么叫网站建设方案书,网站开发软硬件1.函数调用运算符#xff08;#xff09;也可以重载 2.由于重载后使用方式非常像函数的调用#xff0c;因此也称为仿函数 3.仿函数没有固定写法#xff0c;非常灵活
C函数调用运算符重载代码如下#xff1a;
#include iostream
using namespace std;
#include 也可以重载 2.由于重载后使用方式非常像函数的调用因此也称为仿函数 3.仿函数没有固定写法非常灵活
C函数调用运算符重载代码如下
#include iostream
using namespace std;
#include cstring
//函数调用运算符重载class MyPrint {public://重载函数调用运算符void operator()(string test) {cout test endl;}
};void MyPrint02(string test) {cout test endl;
}void test01() {MyPrint myprint;myprint(hello world);//由于使用起来非常类似于函数调用因此称为仿函数MyPrint02(hello world);
}//仿函数非常灵活没有固定写法
//加法类
class MyAdd {public:int operator()(int num1, int num2) {return num1 num2;}
};void test02() {MyAdd myadd;int ret myadd(100, 100);cout ret ret endl;//匿名函数对象//类型() 为匿名对象cout MyAdd()(100, 100) endl;}int main() {test01();test02();return 0;
}