我试图完全重新提出这个问题。情况如下:
class Departure {
private :
unsigned int supply;
public :
Departure(int);
~Departure();
int getSupply() {
return supply;
};
};
class Route {
private :
Departure* departure;
public :
Departure& getDeparture() {
return *departure;
};
};
class Plan {
private :
std::map<Route*, double> quantities;
public :
void addRoute(Route& rt) {
quantities.insert(std::pair<Route*,double>(&rt,0));
};
void createSolution() {
std::map<Route*, double>::iterator it;
for(it = quantities.begin(); it != quantities.end(); ++it) {
it->second = it->first->getDeparture().getSupply();
};
};
添加路线后 - 我已经检查过,它工作正常,我得到一个段错误,从我的试错到现在位于it->first->getDeparture().getSupply()
调用中。任何解释为什么?