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

Recommended Answers

All 2 Replies

How are you storing the 8 teams?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.