“ () ”操作符:能够实现将对象当作函数进行使用。
class Point1
{
public:
Point1() :x(0), y(0){}
Point1(int x_, int y_) :x(x_), y(y_){}
~Point1(){}
inline Point1 operator + (const Point1 &t)const
{
Point1 temp;
temp.x = this->x + t.x;
temp.y = this->x + t.y;
return(temp);
}
inline Point1 operator ()(int xy)const
{
return xy*xy;
}
inline Point1 operator ()(int a, int b, int c = 100)const
{
return a - b + c;
}
void setValue(const int x1, const int y1)
{
x = x1;
y = y1;
}
int getValue()const
{
std::cout << x << std::endl;
std::cout << y << std::endl;
}
private:
int x;
int y;
};