- 论坛徽章:
- 0
|
看STL list node的定义:
struct _List_node_base
{
_List_node_base* _M_next; ///< Self-explanatory
_List_node_base* _M_prev; ///< Self-explanatory
static void
swap(_List_node_base& __x, _List_node_base& __y);
void
transfer(_List_node_base * const __first,
_List_node_base * const __last);
void
reverse();
void
hook(_List_node_base * const __position);
void
unhook();
};
template<typename _Tp>
struct _List_node : public _List_node_base
{
_Tp _M_data; ///< User's data.
};
疑问:
1)User's data为什么是public,而不是private + friend class?
2)swap(), transfer(), reverse(), hook() 和 unhook()都是用来做什么的?
3) 为什么没有constructor?
另外看list源程序中的注释:
* Second, a %list conceptually represented as
* @code
* A <---> B <---> C <---> D
* @endcode
* is actually circular; a link exists between A and D. The %list
* class holds (as its only data member) a private list::iterator
* pointing to @e D, not to @e A! To get to the head of the %list,
* we start at the tail and move forward by one. When this member
* iterator's next/previous pointers refer to itself, the %list is
* %empty. @endif
如果没有直接指向head的指针,是否在list头和尾操作的效率不一样?
谢谢! |
|