The argument that is passed to class Rock is a vector<vector<unsigned int> >
population is defined as:
const std::vector<std::vector<unsigned int> > * population;
In constructor:
Rock::Rock ( const vector<vector<unsigned int> > & v):
population (&v)
{
cout << "constructor: population.size: " << population->size() << " population[0].size: " << (*population)[0].size() <\
< endl;
}
which prints out:
constructor: population.size: 500 population[0].size: 4
Afterwards, in the next member function that is called after constructor:
population.size(): 500 population[0].size() 18446744073709533580
What I thought is that population would keep a copy of the address of the vectorthat is passed to Rock and that it would keep it throughout the class member functions. But it seems that it looses track of its second order elements.
What is wrong with this? How can I correct this? I'd like not to have to alter population type of variable, otherwise the subsequent code has to be adjusted too.
Edit 0: The full code of constructor:
Rock::Rock ( const vector<vector<unsigned int> > & v, const map<unsigned int, AttType>& m, string f ) :
// Default values for Rock parameters.
population (&v),
att_type ( m ),
initial_pos (75000),
population_size (500),
sample_size (200),
theta (0.2),
nr_clusters (4),
max_dif (500),
label_as ("neighbors"),
debug (false)
{
resetBestPair();
worst_pair.p1 = __INT_MAX__;
worst_pair.p2 = __INT_MAX__;
worst_pair.goodness = __DBL_MIN__;
cfg_file = f;
parseConfig ();
cout << "constructor: population.size: " << population->size() << " population[0].size: " << (*population)[0].size() <\
< endl;
}
vceased to exist.Rock.Rock fun() { vector<T> some_vec; return Rock(some_vec); // oops }