gpt4 book ai didi

c++ - "redo/undo"函数的问题(mfc、c++)

转载 作者:行者123 更新时间:2023-11-28 05:30:45 25 4
gpt4 key购买 nike

我试图在我的 mfc 应用程序中创建重做/撤消功能,但是当我试图撤消 CLine 对象时 - 它无法正常工作。我做错了什么?对不起我的英语!

enter image description here

void CKonokhovDoc::OnEditUndo()
{
// TODO: Add your command handler code here
int Index = (int)m_LineArray.GetUpperBound();
int Index2 = (int)m_LineArray_redo.GetUpperBound();
if (Index>-1){
redoLine = m_LineArray.GetAt(Index);
m_LineArray_redo.SetAt(Index2+1,redoLine);
m_LineArray.RemoveAt(Index);
}
UpdateAllViews(0);
SetModifiedFlag();
}


void CKonokhovDoc::OnUpdateEditUndo(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable((int)m_LineArray.GetSize());

}


void CKonokhovDoc::OnEditRedo()
{
// TODO: Add your command handler code here
int Index = (int)m_LineArray.GetUpperBound();
int Index2 = (int)m_LineArray_redo.GetUpperBound();
m_LineArray.SetAt(Index+1, m_LineArray_redo.GetAt(Index2));
m_LineArray_redo.RemoveAt(Index2);
//redoLine = NULL;
UpdateAllViews(0);
SetModifiedFlag();
}

最佳答案

如前所述,SetAt 访问了越界索引,这导致 VS 发出断言调用。使用 Add 自然可以解决问题,因为数组已扩展。

<子> This was mentioned by the OP

关于c++ - "redo/undo"函数的问题(mfc、c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com