重载 -> 运算符
示例如下
- 不能是静态函数
- 返回 T的指针,再调用T->
<type T>
class Pointer
{
Pointer(const T* t) : _target(t)
T * operator ->()
{
return _target
}
T* _target;
};
This is the only really tricky one. It must be a nonstatic member function, and it takes no arguments. The return value is used to perform the member lookup.
If the return value is another object of class type, not a pointer, then the subsequent member lookup is also handled by an operator-> function. This is called the “drill-down behavior.” The language chains together the operator-> calls until the last one returns a pointer.
ref
- https://stackoverflow.com/questions/8777845/overloading-member-access-operators