Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Boost::Intrusive 库中的基本钩子和成员钩子有什么区别,什么时候使用一个比另一个更好?
我已经阅读了 boost 文档,但它不是那么解释性的。
据我所知,这是风格和面向对象设计的问题。基本挂钩侵入了继承层次结构,需要一个额外的public父类,并可能在设计上强制多重继承。使用成员挂钩允许程序员将对象视为has-a与容器有关系,而不是is-a与容器成员关系。
public
has-a
is-a
恕我直言,如果您的对象仅打算包含在单个容器中,则基本挂钩似乎更方便。否则(对于多个容器),多个成员钩子提供不那么模棱两可的解决方案(因为避免了多重继承)
http://www.boost.org/doc/libs/1_47_0/doc/html/intrusive/recursive.html “成员挂钩不适合递归结构”