class StrBlobPtr { public: std::string& operator*() const { auto p = check(curr, "dereference past end"); return (*p)[curr]; } std::string* operator->() const { return & this->operator*();//将实际工作委托给解引用运算符 } };
一般情况下,这两种运算符是类的成员
对箭头运算符返回值的限定
对于重载了箭头运算符的类。形如point->mem有两种可能的执行方式:
(1)point为内置类型的指针,则先解引用point,再寻找mem成员
(2)point为类对象,先调用重载的箭头运算符,根据结果再寻找mem