Tôi đang khám phá boost :: iterator_facade và tình cờ gặp chút mã này:`template <class> lớp người bạn Foo` có nghĩa là gì?
friend class boost::iterator_core_access;
template <class> friend class Iterator;
không dòng thứ hai có ý nghĩa gì? Tôi quen thuộc với các lớp bạn bè, nhưng tôi không nghĩ rằng tôi đã nhìn thấy template <class>
trước bất cứ điều gì trước đây.
Dưới đây là bối cảnh:
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;
http://en.cppreference.com/w/cpp/language/friend – chris
'lớp node_iter' là một người bạn ở đây.Dường như dòng này có thể dư thừa như một lớp là một người bạn với chính nó theo mặc định –