Boost :: Fibonacci_Heap :: top()对象在赋值之前被销毁

时间:2015-01-10 01:49:49

标签: c++ c++11 boost

我在类方法中有以下循环:

vector<PuzzleImpl> PuzzleImpl::performMove()
{
    //! Remove a single move from mMoves and store it in aMove.
    MovesImpl aMove = mMoves.top();
    mMoves.pop();

    //! Cached local variables.
    vector<size> soln = aMove.getSoln();
    size RID = aMove.getRowID();
    size CID = aMove.getColID();
    size BID = aMove.getBlockID();
    bool solvable = true;

    //! Return Vector, will store all possible moves from aMove.
    vector<PuzzleImpl> neighbours;

    //! Build all Boards and update Moves Queue for a move from top of mMoves.
    while (!soln.empty()) {
        //! Store local copies to update without being destructive to original.
        // Also reset updatedMoves and updatedBoard for next iteration.
        fib_heap tempHeap = mMoves;
        fib_heap updatedMoves;
        Board<size> updatedBoard = mBoard;

        //! Get a <value>, remove it form <soln>.
        size value = soln.back();
        soln.pop_back();

        //! Update Board with the move.
        updatedBoard.set(RID, CID, value);

        //! Iterate through the mMoves queue and update for the removed move.
        while (!tempHeap.empty()) {
            //! Get an element, remove it from the heap.
            MovesImpl temp = tempHeap.top();
            tempHeap.pop();

            //! If the temp object shares the same RID/CID/BID remove <value>.
            if ((temp.getRowID() == RID) || (temp.getColID() == CID) 
                                                || (temp.getBlockID() == BID)) {
                temp.removeMove(value);
            }

            //! Check if we can solve the puzzle form this position. If you have
            //  a blank position left but there are have no moves from that
            //  position, a solution is unattainable. - HALT.
            if (temp.getSolnSize() == 0) {
                solvable = false;
                break;
            }

            //! Add the Moves object to the updatedMoves Heap.
            updatedMoves.push(temp);
        }

        //! If the puzzle is solvable from this position with the current move,
        //  generate new PuzzleImpl object using the Board and Moves Vec.
        neighbours.push_back(PuzzleImpl(updatedBoard, updatedMoves, solvable));
    }

    //! Return the Vector containing all possible states from this move.
    return neighbours;
}

我遇到的问题是:

MovesImpl temp = tempHeap.top();

我收到访问冲突(访问冲突读取位置0x0000000C。),说明无法读取&lt; src &gt;的内存并且&lt; this &gt ;在内存中设置为随机值。 MovesImpl没有任何堆分配,它基于堆栈,因此我使用默认赋值运算符。我已经指定了副本ctor。

有什么想法吗?输入非常感谢。

/谢谢!

0 个答案:

没有答案