#include<bits/stdc++.h>
using namespace std;
//函数调用运算符重载
//打印输出类
class MyPrint{
public:
void operator()(string test){
cout<<test<<endl;
}
void aa(string test){
cout<<"AA"<<endl;
}
};
void test01(){
MyPrint myprint;
myprint("hello world");
//myprint.aa("hello world");
//由于使用起来非常类似于函数调用,因此也称为仿函数
}
int main()
{
//函数调用运算符重载
//函数调用运算符()也可以重载
//由于重载后使用的方式非常像函数的调用,因此称为仿函数
//仿函数没有固定写法,非常灵活
test01();
return 0;
}
09-16
525
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-15
141
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交