C++智能指针读书笔记

2020-01-06 14:01:15于海丽
  •   }            // 解引用,make_shared获取vector,用下表运算符返回curr位置上的对象    StrBlobPtr& incr() { 
  •     check(curr, "increment past end of StrBlobPtr");      ++curr; 
  •     return *this;    } 
  •   bool operator!=(const StrBlobPtr& p) { return p.curr != curr; }   
  • private:    weak_ptr<vector<string>> wptr; 
  •   size_t curr;    shared_ptr<vector<string>> check(size_t i, const string& msg) const 
  •   {      auto rent = wptr.lock(); 
  •     if (!rent)        throw runtime_error("unbound StrBlobPtr"); 
  •     if (i >= rent->size())        throw out_of_range(msg); 
  •     return rent;    } 
  • };  StrBlobPtr StrBlob::begin() 
  • {    return StrBlobPtr(*this); 
  • }  StrBlobPtr StrBlob::end() 
  • {    return StrBlobPtr(*this, data->size()); 
  • }  ?

    注:相关教程知识阅读请移步到C++教程频道。