common question?
Jul 13, 2009 at 7:47am UTC
it's not changing in main after OBJ_NUM is decreased by 1 in function chk_brd().
but obs_x and obs_y are works true. I wanna to decrease OBJ_NUM in function and use decreased OBJ_NUM in main.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
void chk_brd(vector<vector<int > > &obs_x, vector<vector<int > > &obs_y,
int * xe, int * ye,
int l_x, int l_y, int OBJ_NUM)
{
int b = 0;
for (int j = 0; j < OBJ_NUM; j++)
{
if (xe[j] == l_x || xe[j] == 0 || ye[j] == l_y || ye[j] == 0)
{
obs_x.erase(obs_x.begin()+j);
obs_y.erase(obs_y.begin()+j);
b++;
}
}
OBJ_NUM -= b; //??
}
int main()
{
chk_brd(obs_x, obs_y, xe, ye, l_x, l_y, OBJ_NUM); // ??
}
Last edited on Jul 13, 2009 at 10:43am UTC
Jul 13, 2009 at 9:47am UTC
If OBJ_NUM has the same value of the number of elements in the arrays, you don't need to pass it seperately. The index should decrease too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void chk_brd(vector<vector<int > > &obs_x, vector<vector<int > > &obs_y,
int * xe, int * ye,
int l_x, int l_y)
{
for (int j = 0; j < obs_x.size(); ++j)
{
if (xe[j] == l_x || xe[j] == 0 || ye[j] == l_y || ye[j] == 0)
{
obs_x.erase(obs_x.begin()+j);
obs_y.erase(obs_y.begin()+j);
--j;
}
}
}
int main()
{
chk_brd(obs_x, obs_y, xe, ye, l_x, l_y);
}
Jul 13, 2009 at 11:02am UTC
thnks but I need to pass OBJ_NUM too.
Last edited on Jul 13, 2009 at 11:02am UTC
Jul 13, 2009 at 4:25pm UTC
How does OBJ_NUM relate to the size of the vectors? If you're using OBJ_NUM to iterate the vectors.
At any rate, you just need to decrement j as it's incremented at the end of the loop.
Topic archived. No new replies allowed.