运算符+号重载例子:
计算复数相加,当运算符重载之后,在调用该运算符时自动调用该函数。(这句话理解了,代码就容易懂了)
#include <iostream>
using namespace std;
class F
{
public:
int operator() (int a, int b)
{
return a*a + b*b;
}
};
class F2
{
public:
int MemFunc(int a, int b)
{
return a*a + b*b;
}
};
void main()
{
F f;
f(2, 4);
F2 f2;
f2.MemFunc(2, 4);
//
//operator() (int a, int b)
cout<<"hello..."<<endl;
system("pause");
return ;
}