草庐IT

c++ - 列表中 -> 运算符的语义(以及一般的 C++)

我目前的任务是编写一个带有迭代器的列表。与创建迭代器类一样,列表不是问题。从几个来源,我看到我有两个运算符要在我的迭代器类中定义:operator*和operator->。到目前为止太棒了!假设我的迭代器结构是这样的//NestedclassofListclass_Iter{private:ListElem*pCurr;constList*pList;public:_Iter(ListElem*pCurr,constList*list):pCurr_(pCurr),pList(list){}T&operator*(){returnpCurr_->data;}T*operator->()