【发布时间】:2014-06-06 01:17:58
【问题描述】:
我正在探索 boost::iterator_facade 并遇到了这段代码:
friend class boost::iterator_core_access;
template <class> friend class Iterator;
第二行是什么意思?我对朋友班很熟悉,但我想我以前没有在任何东西前面看到过template <class>。
这是上下文:
template <class Value>
class node_iter
: public boost::iterator_facade<
node_iter<Value>
, Value
, boost::forward_traversal_tag
>
{
public:
node_iter()
: m_node(0) {}
explicit node_iter(Value* p)
: m_node(p) {}
template <class OtherValue>
node_iter(node_iter<OtherValue> const& other)
: m_node(other.m_node) {}
private:
friend class boost::iterator_core_access;
template <class> friend class node_iter;
template <class OtherValue>
bool equal(node_iter<OtherValue> const& other) const
{
return this->m_node == other.m_node;
}
void increment()
{ m_node = m_node->next(); }
Value& dereference() const
{ return *m_node; }
Value* m_node;
};
typedef impl::node_iterator<node_base> node_iterator;
typedef impl::node_iterator<node_base const> node_const_iterator;
【问题讨论】:
-
class node_iter是这里的朋友。看起来这条线可能是多余的,因为默认情况下一个类是它自己的朋友