Click to See Complete Forum and Search --> : Simple Vector Problem


tilt
June 19th, 2006, 02:17 PM
New to C++ and Programming in General. Have a quick question about my code.


//Legal Move Generator
void legal_move(vector<int> &move, position board[], int size);

//Generate Moves
void legal_move(vector<int> &move, position board[], int size){
int counter = 0;
for(counter; counter <= size; counter++){
if(board[counter].occupied == 0){
//Assign the value of counter to the vector move, and so on
}
}
}


I would just use an array in the function, but obviously the legal moves will grow and shrink, so I thought a vector would be a better fit. The question is in the comment under the if condition--

Thanks for any help.

dude_1967
June 19th, 2006, 03:53 PM
tilt,

Your question is unclear. Please phrase your question in the form of a question.

Chris.

tilt
June 19th, 2006, 03:58 PM
Opps, thanks for the help though. Got it.

Paul McKenzie
June 19th, 2006, 04:14 PM
Still, I don't know how to assign the square numbers to the vector:So learn with a small test program. You should start out with a simple example of how to use a vector instead of putting a live (or developing) application through this learning process. Once you know how to use vector, then and only then should you use it in a larger application.

#include <vector>

void foo(std::vector<int>& v)
{
// what do you want to do with v?
}

int main()
{
std::vector<int> MyVect;
//...
foo( MyVect );
}
//...etc

Now, from this simple program, what exactly is it you want to do? Whatever it is, you can test it very easily, all without bringing up game boards, occupied squares, etc.

So is MyVect empty? Does it already have data?

Regards,

Paul McKenzie

tilt
June 20th, 2006, 09:41 PM
Thanks for the advice Paul, I appreciate that.