I'm playing around with genetic algorithms, and like always, i'm trying to templatize part of it. Although I'll probably abandon this code because I don't like where it's going, I'm still curious as to how I can get it to compile.
The problem I'm having is passing the template argument to "float fitness_score(Chromo<>:naType)". As is, i get the error:
37 C:\compilers\bloodshed\main.cpp invalid conversion from `float (*)(Chromo<32>:naType)' to `float (*)(Chromo<16>:naType)'
I've tried just about all I know, but I can't seem to get it to compile.
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
template<int FieldSize = 32>
class Chromo
{
public:
struct DnaType{ unsigned dt_dna: FieldSize; };
Chromo(void) : geneCount(FieldSize){}
Chromo(const Chromo<> &s) : geneCount(s.geneCount)
{dna = s.dna;}
float score(float (*sc)(DnaType));
private:
unsigned dna : FieldSize;
const int geneCount;
};
float fitness_score(Chromo<>::DnaType dt)
{
//dummy function
return 1.2f;
}
int main(int argc, char *argv[])
{
const int x = 16;
Chromo<x> ccc;
cout << ccc.score(fitness_score) << endl;
system("PAUSE"); //dev-c++ generated
return EXIT_SUCCESS;
}
Any ideas?