上一次是双向链表dList泛型迭代
template<class T>
class dListNoteIterator_
{
private:
dListNote_<T>* _pNote;
public:
/// <summary>
/// 构造函数,传值迭代器管理的值
/// </summary>
/// <param name="pNote"></param>
inline dListNoteIterator_(dListNote_<T>* pNote) { _pNote = pNote; }
/// <summary>
/// 比较实现
/// </summary>
/// <param name="that"></param>
/// <returns></returns>
bool operator != (const dListNoteIterator_& that) { return _pNote != that._pNote; }
/// <summary>
/// 自增实现
/// </summary>
/// <returns></returns>
inline dListNoteIterator_& operator ++ () { _pNote = _pNote->Next; return *this; }
/// <summary>
/// 解引用,取值
/// </summary>
/// <returns></returns>
T& operator * () { return _pNote->Data;}
//LDIterator(const LDIterator&) = delete;
//LDIterator& operator=(const LDIterator&) = delete;
//~LDIterator() = default;
};
字符串类str_:charIterator_
class charIterator_
{
private:
char_* _pChar;
public:
/// <summary>
/// 构造函数,传值迭代器管理的值
/// </summary>
/// <param name="pNote"></param>
inline charIterator_(char_* pChar){ _pChar = pChar;}
/// <summary>
/// 比较实现
/// </summary>
/// <param name="that"></param>
/// <returns></returns>
bool operator != (const charIterator_& that){return _pChar != that._pChar; }
/// <summary>
/// 自增实现
/// </summary>
/// <returns></returns>
inline charIterator_& operator ++ (){ ++_pChar; return *this; }
/// <summary>
/// 解引用,取值
/// </summary>
/// <returns></returns>
inline char_& operator * (){ return *_pChar; }
//LDIterator(const LDIterator&) = delete;
//LDIterator& operator=(const LDIterator&) = delete;
//~LDIterator() = default;
};
在类 str_中代码:
实例:
输出: