传递给的参数class Rock
是vector<vector<unsigned int> >
population
定义为:
const std::vector<std::vector<unsigned int> > * population;
在构造函数中:
Rock::Rock ( const vector<vector<unsigned int> > & v):
population (&v)
{
cout << "constructor: population.size: " << population->size() << " population[0].size: " << (*population)[0].size() <\
< endl;
}
打印出来:
constructor: population.size: 500 population[0].size: 4
之后,在构造函数之后调用的下一个成员函数中:
population.size(): 500 population[0].size() 18446744073709533580
我的想法是保留传递给population
的地址的副本,并将其保留在整个类成员函数中。但它似乎失去了对其二阶元素的跟踪。vector
Rock
这有什么问题?我该如何纠正?我不想改变population
变量的类型,否则后续代码也必须调整。
编辑0:构造函数的完整代码:
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;
}