0

OK、ここに私の問題があります:

  • 「subMove」を指すMove class変数を使用して、を実装しましたMove *subMove
  • 私はリストを持っています(私がループしている s を使用しvectorて)Movevector<Move>::iterator
  • グローバルなMove オブジェクト(リンクされたリストの「ルート」としましょう) があり、関数が最初に呼び出されます。
  • 現在の移動 (ループから) を現在のルートのsubMove フィールドに割り当てようとしています。

そして、ここで問題が発生する方法は...

私のコードは(大まかに)次のようになります。

int 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;
}

何か案は?

4

0 に答える 0