Thread: copy constructor doesn't invoke

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265

    copy constructor doesn't invoke

    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! (:
    Last edited by gavra; 06-06-2013 at 12:24 PM.
    gavra.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy constructor and new
    By Memloop in forum C++ Programming
    Replies: 10
    Last Post: 09-13-2009, 10:23 AM
  2. Copy Constructor
    By noobcpp in forum C++ Programming
    Replies: 3
    Last Post: 07-01-2007, 06:29 AM
  3. Copy constructor
    By dude543 in forum C++ Programming
    Replies: 26
    Last Post: 01-26-2006, 05:35 PM
  4. what is copy constructor?
    By Tonyukuk in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2002, 05:54 PM
  5. copy constructor
    By ygfperson in forum C++ Programming
    Replies: 6
    Last Post: 03-05-2002, 06:55 PM