[Dev-C++] Another newbie question about fn's returning STL containers
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Matt K. <sy...@as...> - 2003-10-25 06:00:49
|
I'm generating a stack of custom board class objects, and was wondering what the proper way to do this is (this is all for a board game-- tic-tac-toe in this case). What I have is a board member function called Generate_Moves that returns a stack of boards (ie. stack<board> ) of new possible selections. In the calling fn, I have a passed in variable of type board called state and do this: stack<board> moves; moves = state.Generate_Moves( p ); // p is the player whose turn it is Is this valid? Or should I be making "moves" a pointer, and then return a pointer to the new stack from Generate_Moves (and call delete on it when I'm done ? ). I was thinking that the way I have it right now is going to lose the "moves" stack in memory and cause a leak because it will add another lost guy every time the containing fn is called.... Implementing this minimax algorithm for tic-tac-toe was so much simpler in LISP :( |