函数操作符()可以实现将对象当函数来使用
#include <iostream>
using namespace std;
class Square{
public:
double operator()(double x)const{
return x * x;
}
int operator()(int a,int b,int c = 9){
return a + b - c;
}
};
int main(void){
Square square;
cout << square(12.) << endl; //144
cout << square(10, 20, 30) << endl; //0
cout << square(10, 20) << endl; // 21
return 0;
}