C++Primer-成员访问运算符

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

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务