函数操作符:()
可以实现将对象当函数来使用
代码如下
/*func_operator.cpp*/
1 #include <iostream>
2 using namespace std;
3 class Square{
4 public:
5 double operator()(double x)const{
6 return x*x;
7
8
9 }
10 int operator()(int a,int b,int c = 9){
11 return a + b - c;
12 }
13
14 };
15 int main(void){
16 Square square;
17 cout << square(12.) << endl; //144
18 cout << square(10,20,30) << endl; //0
19 cout << square(10,20) << endl; // 21
20 return 0;
21 }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。