一般操作符*返回的是对象的引用 ,而->返回的是对称的指针
以Test类为例
class Test
{
public:
Test() :a(0), b(0) {}
Test& operator*()
{
cout << "operator*" << endl;
return *this;
}
Test* operator->()
{
cout << "opertator->" << endl;
return this;
}
int a, b;
};
测试例子为:
Test t;
cout << t->a << endl;
cout << (*t).a << endl;
输出为
operator->
0
operator*
0