Question on intrusive hooks

I'm trying to come to grips with using the boost intrusive containers, but I don't think I understand how the lifetime of hooks need to be managed. This piece of code fails the !hook.is_linked() assertion:
Any pointers? Also, is there is a non-intrusive AVL tree container as part of boost?
struct my_node_t {
int i_;
my_node_t(int i): i_(i) {}
friend bool operator<(const my_node_t& lhs, const my_node_t& rhs) {
return lhs.i_ < rhs.i_;
}
friend ostream& operator<< (ostream& os, const my_node_t& n) {
return os << n.i_;
}
};
int main() {
avltree

bsing escribió:
I'm trying to come to grips with using the boost intrusive containers, but I don't think I understand how the lifetime of hooks need to be managed.
The node is being destroyed (note vec is destroyed before tree) while inserted in "tree". That's a lifetime error, you are end up storing garbage in the tree after vec is destroyed. Just change the order of the first lines. Best, Ion
participants (2)
-
bsing
-
Ion Gaztañaga