hello, i'm stumped and hoping that someone can help me out... i've created a class called IntState, which stores the state of a system a second class Optimization performs an optimization algorithm on an original system state to find the state of optimum reliabilty... however, i'm having a major problem...
when executing the following (psuedo)code, the method makes changes to the currentState object as well as the state object, even though currentState is never modified, and is used only to supply a copy.
public IntState getNextState( IntState currentState ) IntState state = currentState.copy(); modify state return state
anyone have any ideas??? i'm getting really desperate and would really appreciate it... thanks in advance. mike
Does your copy() have the same functionality of a clone() method? If so why not use a clone() method instead? Are you using deep or shallow copying? I think you have to be cafeful if you're deep-copying. [ April 07, 2005: Message edited by: Yevgeniy Treyvus ]
Joined: Jul 22, 2004
i've made a little progress, i think the problem is that i'm making a shallow copy, but i need to be making a deep copy... do you know of any simple ways to do this??
Here is a method that I wrote in one of my framework utilities. This is a simple way of making a deep copy. If performance is critical, there are faster ways of doing this.........but this should get you past your problem.