operator
operator 有两种用法。
1.operator overloading(操作符重载)
struct A
{
int nPrice;
int flag;
A()
{
memset(this,0,sizeof(A));
}
bool operator == (const A &x)
{
return nPrice == x.nPrice
&& flag == x.flag
}
};
2.operator casting(操作隐式转换)
class A
{
public:
operator B*() {return this->b_}
};
A a;
当if(a),编译时,它转换为if(a.operator B*()),其实就是判断if(a.b_)。