View Single Post
Old Sep 21st, 2007, 9:05 AM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
That's a lot of code to try to make sense of, but this:
   public static GridNode copy(GridNode a)
   {
      GridNode b = a;
      return b;
   } // end copy
will be a shallow copy. In other words, b and a will refer to the same thing. Similarly, here,
   // set leftChild
   public void setLeftChild(GridNode newLeftChild)
   {
      leftChild = newLeftChild;
   } // end setLeftChild
It's difficult to tell, in the second case, whether or not the reference is okay, or a Bad Thang.

When you clone a new GridNode, you need to at least copy the state, not just refer to the source's state.

I also don't know why you're using getters and setters inside the class, where you have access. To me, that just obfuscates things.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote