All pastes #368247 Raw Edit

pgm.h

public cpp v1 · immutable
#368247 ·published 2007-02-22 22:58 UTC
rendered paste body
function in question:void Population::GetStatistics(float* MaxFitness, float* MinFitness, float* AvgFitness){	vector<Individual*>::iterator iter;	float tot = 0.0f;	int count = 1;	iter = Individuals->begin();@@	*MaxFitness = *iter->GetFitness();	*MinFitness = *MaxFitness;	while(iter != Individuals->end()){		if(iter->GetFitness() > MaxFitness){MaxFitness = iter->GetFitness();}else		if(iter->GetFitness() < MinFitness){MinFitness = iter->GetFitness();}		tot += iter->GetFitness();		count++;		iter++;	}	*AvgFitness = (tot/(float)count);}Error:/home/cripps/Class/MUN/CS3710/ass4/geneticalgorithm/src/Population.cpp: In member function &#8216;void Population::GetStatistics(float*, float*, float*)&#8217;:/home/cripps/Class/MUN/CS3710/ass4/geneticalgorithm/src/Population.cpp:89: error: request for member &#8216;GetFitness&#8217; in &#8216;* iter. __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Individual**, _Container = std::vector<Individual*, std::allocator<Individual*> >]()&#8217;, which is of non-class type 'Individual*'what's going on:Individual is a class as part of a genetic algorithm.Individuals is a vector declared as so: vector<Individual*>* Individuals = new vector<Individual*>;thus, *iter should give access to an element of the vector Individuals, thus *iter->GetFitness(); shouldcall the "GetFitness()" function (that does exist).