链接列表,矢量和指针的问题

时间:2013-01-30 12:19:57

标签: c++ class pointers vector

好的,这是我的问题:

  • 我实施了Move class,变量Move *subMove指向“subMove”
  • 我正在使用vector
  • 列出Move vector<Move>::iteratorint Game::doSth(Move & pv) { vector<Move> moves; this->possibleMoves(moves); for (std::vector<Move>::iterator move = moves.begin(); move!=moves.end(); ++move) { // Do sth int subResult = this->doSth(*move); if (someConditionIsTrue) { // yep, we want to store THIS move as a submove // This works - without memory errors - // but still something goes weird, so I'd prefer creating a new object pv.subMove = &(*move); // Also tried something along the lines of `pv.subMove = new Move(*move)` // - yes there is an appropriate copy constructor - // but this leads to a `segmentation fault` error } } // return something; }
  • 我有一个全局移动对象(比如说我们链接列表的'root'),我们的函数最初被称为
  • 我正在尝试将当前移动(从循环中)分配到当前根目录的 subMove字段

以下是问题的出现......

我的代码(大致)如下所示:

{{1}}

有什么想法吗?

0 个答案:

没有答案