心烦意乱 进!!

来源:百度知道 编辑:UC知道 时间:2024/06/21 09:17:37
刚刚看STL,程序大概是这样的,定义一个摸板,实现对普通链表的功能扩展!
比如通过++,--使之指向下个节点!下面是伪代码!
struct list_node_base{
list_node_base* M_next;//指向后继节点!
list_node_base* M_prev;
};
template <class T>
struct List_node:public List_base{
T M_data;//元素!
}
以上是节点!
struct List_iterator_base{
List_node_base *M_node;
构造函数。。
然后再定义两个函数,用来使M_node指向下个 元素和前面的元素!还有判断==,!=等重载操作符!
}
template<class T,class Ref,class Ptr>
struct List_iterator:public List_iterator_base{
typedef List_iterator<T,T&,T*> iterator;//就是这里不明白这样定义别名什么意思,还有为什么这个结构体为什么要有三个摸板参数!
。。。
下面就是定义各种操作符!

1.定义别名是为了方便。比如说,我要定义一个list的迭代器,完整的就得这样:
list::list_iterator<参数,参数,参数>..
现在可以这样:list::iterator...

2.为什么有三个参数。
因为template<class T,class Ref,class Ptr>
这里有三个参数。看明白了吗?