0

i am trying to figure out how to pass structures based on the state of one of the variables.
bassically there are 8 "teams" that each have a "progress" variable that is a bool. I want to be able to pass the 4 "teams" that have had their "progress" bool set to true. I have looked into just doing this with if statements but I would rather avoid having to write out the 70 possible combinations of teams :/ is there a way to write a conditional that will bassically pass any "teams" with a true "progress" into a function. If anyone has any alternative suggestions that won't require a full re write of the code I would much appreciate hearing them.

cheers
Dan

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nmaillet
0

Assuming you are using an array of pointers (you could easily modify if you are storing the structures themselves):

int count = 0;
for(int i = 0; i < size; i++)
    if (teams[i]->progress)
        count++;
Team **teamsSubset = new Team*[count];
for(int i = 0, i2 = 0; i < size; i++)
    if (teams[i]->progress)
        teamsSubset[i2++] = teams[i];
some_function(teamsSubset, count);

I didn't compile this, so there may be some issues, but hopefully you get the general idea. Even simpler, you could use a list, vector, etc. from the STL.

Edited by nmaillet: Added link to STL reference.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.