重载函数调用符号(仿函数)

重载函数调用符号(仿函数)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>


using namespace std;

class A
{
public:
A();
~A();
//重载一个伪函数
int operator()(int value) {
return value * value;
}
private:
int a;
};

A::A()
{
}

A::~A()
{
}

int main(char *argv[], int argc)
{
A a;

cout << a(2) << endl;

return 0;
}