1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <iostream>
using namespace std;
class Square{
public :
double operator()( double x) const {
return x * x;
}
int operator()( int a, int b, int c=0) const {
return a+b-c;
}
};
int main( void ){
Square sq;
//括号里面的参数会被自动当作形参传入
cout << sq(12) << endl; //144
cout << sq(1,5,3) << endl; //3
cout << sq(1,3) << endl; //4
return 0;
}
|
花括号操作符重载
最新推荐文章于 2022-12-01 01:37:15 发布