Hi,
My RedBlackTree and RBNode classes has a static instance that represents the Nil of the rbtree (both point to the same node).
I encountered a bug during some tests and it seems that the nil instance is being modified during delete from rbtree (I think).
However, I thought that maybe overloading the copy constructor and making sure that the node is nil creating a new instance will solve the problem.
But the copy constructor doesn't run /:
The base class of BookNode is RBNode.
Here is the relevant definitions:
Code:
RBNode(const RBNode& other)
{
other.CopyTo(this);
}
void RBNode::CopyTo(RBNode* node) const
{
node->left = this->left;
node->right = this->right;
node->parent = this->parent;
node->color = this->color;
}
BookNode(const BookNode& other)
{
other.CopyTo(this);
}
void BookNode::CopyTo(RBNode* node) const
{
if (node == RBNode::myNil)
node = new RBNode();
RBNode::CopyTo(node);
BookNode* the_node = (BookNode*)node;
the_node->book_code = this->book_code;
the_node->customer_pointer = this->customer_pointer;
the_node->book_p2p = this->book_p2p;
}
I remind you that it just doesn't get to the lines above, probably the default conpy constructor is being invoked instead (or maybe not and it just changes pointers? @_@)
Thank you! (: