标题:求解~~~
取消只看楼主
weststreet
Rank: 2
等 级:论坛游民
帖 子:21
专家分:18
注 册:2011-2-9
 问题点数:0 回复次数:1 
求解~~~
下面以List为例说明迭代器的原理
// List节点的定义
template<class T>
struct __list_node {
typedef void* void_pointer;
void_pointer next;
void_pointer prev;
T da
ta;
};
// List迭代器的定义
template<class T, class Ref, class Ptr>
struct __list_iterator {
// 这三个typedef是为了简化后面的代码书写
typedef __list_iterator<T, T&, T*>            iterator;
typedef __list_iterator<T, const T&, const T*>const_iterator;
typedef __list_iterator<T, Ref, Ptr>          self;
typedef bidirectional_iterator_tag iterator_category;    // 迭代器类型属于bidirectional iterator
typedef T value_type;    // 值类型
typedef Ptr pointer;     // 指针类型
typedef Ref reference;   // 引用类型
typedef __list_node<T>* link_type;   // 节点指针类型
typedef size_t size_type;
typedef ptrdiff_t difference_type;
link_type node;  // 迭代器当前所指的节点


//下面三段如何理解?
typedef __list_iterator<T, T&, T*>            iterator;
typedef __list_iterator<T, const T&, const T*>const_iterator;
typedef __list_iterator<T, Ref, Ptr>          self;
2011-04-29 09:33
weststreet
Rank: 2
等 级:论坛游民
帖 子:21
专家分:18
注 册:2011-2-9
得分:0 
坐等高手
2011-04-29 10:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-338326-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.108698 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved