int main() {
bacteria population1[popsize];
for (int i = 0; i < popsize; i++)
population1[i].init();
for (int i = 0; i < popsize; i++)
population1[i].evaluate(population1[]); // it does not work
sort(population1, population1 + popsize, [](bacteria p, bacteria p1) {return p.fitness < p1.fitness; });
for (int i = 0; i <maxgeneration; i++) {
cout << population1[popsize - 1].fitness << endl;
population1[popsize - 1].show();
pg(population1); // population
cout << population1[popsize - 1].fitness << endl;
population1[popsize - 1].show();
}
cout << "phage" << endl;
phage population[popsize];
for (int i = 0; i < popsize; i++)
population[i].init();
for (int i = 0; i < popsize; i++)
population[i].evaluate(b);
sort(population, population + popsize, [](phage p, phage p1) {return p.fitness < p1.fitness; });
for (int i = 0; i <maxgeneration; i++) {
cout << population[popsize - 1].fitness << endl;
population[popsize - 1].show();
pg(population); // population
cout << population[popsize - 1].fitness << endl;
population[popsize - 1].show();
}
The first error that my compiler found is that a primary expression is expected before "]" in line 133.
Maybe it has something to do with your phage struct not containing:
1 2 3 4
void evaluate(phage bla[])
{
fitness = 42;
}
While you are calling a function with the footprint "void evaluate(phage bla[])" that is supposed to be a member of struct population[i] and population[i] is a phage struct.
But like TheIdeasMan pointed out, it could be that you are looking for something completely different because you did not tell us what error you are having trouble with.
The population[] is incorrect. If you're using the square brackets outside of initialization, they should always surround an index into the array. If you're passing an array into a function, there is no reason to use the brackets at all: xx.evaluate(population);.
Of course, that's going to cause you problems too, as Nico noted. elements of population are of type phage and phage doesn't have an evaluate function that takes an array of phage elements.