I want to have singleton class that its object is not statically created. having the following code, when I call ChromosomePool::createPool() I get the following error message :
--> ChromosomePool.h:50: undefined reference to `myga::ChromosomePool::pool' <--
Can anyone please tell me how can I solve the problem ?
class ChromosomePool {
private:
double * array;
const int len;
const int poolSize;
const int chromosomeLength;
static ChromosomePool* pool;
ChromosomePool(int size_of_pool, int length_of_chromosom):
poolSize(size_of_pool) , chromosomeLength(length_of_chromosom),
len(size_of_pool*length_of_chromosom){
array = new double[len];
}
public:
static void createPool(int size_of_pool, int length_of_chromosom) {
if(pool) {
DUMP("pool has already been initialized.");
exit(5);
}
pool = new ChromosomePool(size_of_pool,length_of_chromosom);
}
static void disposePool() {
if( !pool ) {
DUMP("Nothing to dispose");
exit(5);
}
pool ->~ChromosomePool();
pool = NULL;
}
static ChromosomePool* instace() {
if( !pool ) {
DUMP("Using pool before it is initialized");
exit(5);
}
return pool;
}
~ChromosomePool() {
delete[] array;
}
};