working with policy classes
Hello everyone. I'm reading Andrei's Alexandrescu's book on Modern C++
Design and I decided to implemente in my research code the use of
policy classes. My objective is to abstract the storage of all
individuals in a population. To that purpose, I created a Population
class, as follows:
template <class T>
class CreationPolicy
{
public:
void create(size_t);
};
template <class T>
struct StdVectorStorage
{
public:
static std::vector<T>* _pointee;
static void create(size_t p)
{
_pointee = new std::vector<T>();
_pointee->reserve(p);
}
protected:
~StdVectorStorage(){}
};
template
<
class Individual,
template <class> class CreationPolicy = StdVectorStorage>
class Population : public CreationPolicy<Individual>
{
public:
Parameters* _Params;
// initialize population
void initialize(Parameters* p)
{
// assign pointer to parameter list
_gaParams = p;
// create population according to the CreationPolicy
this->create((size_t)_gaParams->get(popSize));
}
};
For some reason, if I try to use the _pointee value within initialize I
get a compiler error. From the user point of view, I don't want to
include another parameter for the instantiation of the Population class
(that's why I didn't include a Pointer parameter and a Pointer*
_variable within the class. Can anyone give me a hand on this? Thank
you very much,
Alejandro M. Arag?n
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]