use non-static member function as the objective function

Wu Ruoyun MRYWu at ntu.edu.sg
Fri Apr 20 21:21:48 EDT 2001


Dear All:

Is that possible to use a non-static member function as the objective
function?  I need the objective function non-static, so that it can access
instance members of the class.  I always got compilation error when trying
to do so.  The code might like the following:

In the header file we have:

class SearchEngine
{
private:
	GAGenome		*theGenome;
	GAGeneticAlgorithm		*theGA;

	float objectiveFunction(Genome &c);

public:
	void configureGA();
}

then in the cpp file:

void SearchEngine::configureGA()
{
	GARealAlleleSetArray alleles;
	...
	theGenome = new GARealGenome(alleles,
SearchEngine::objectiveFunction);
	// I also have try "&SearchEngine::objectiveFunction" and
"objectiveFunction", but still didn't work.
	...
}

float SearchEngine::objectiveFunction(Genome &c)
{
	// calculating fitness score
}







More information about the galib mailing list