oyjpArt ACM/ICPC算法程序设计空间

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

记录一个bug

Posted on 2009-10-24 02:05 oyjpart 阅读(2741) 评论(0)  编辑 收藏 引用 所属分类: 程序设计

 vector<SyllState> StateQueue;

 StateQueue.reserve(m_psz.GetLength());
 StateQueue.push_back(SyllState(_T(""), iEndCharIdx));
 BOOL bExit = FALSE;
 INT iBegin = 0;
 while(iBegin < (INT)StateQueue.size() && !bExit)
 {
  INT& iIndex = StateQueue[iBegin].iIndex;
  CString& strSyll = StateQueue[iBegin].strSyll;

  iBegin++;

  INT& nNumOfPres = m_pNumOfPre[iIndex];
  for(INT i = 0; i < nNumOfPres; ++i)
  {
   INT& nPre = m_pPre[iIndex][i];
   if(nPre < iBegCharIdx) continue;

   if(nPre == iBegCharIdx)
   {
    CString strSyllFound = m_psz.Mid(nPre, iIndex - nPre) + _T("\'") + strSyll;
    vecSubSyllable.Add(strSyllFound.Left(strSyllFound.GetLength()-1));
    if(vecSubSyllable.GetCount() >= MAX_SYLLABLE_NUM)
    {
     bExit = TRUE;
     break;
    }
   }
   else
   {
    StateQueue.push_back(SyllState(
     m_psz.Mid(nPre, iIndex - nPre) + _T("\'") + strSyll,
     nPre));
   }
  }
 }


上述代码有问题吗?
有。拿的是vector的引用,但是vector自动扩容去了,结果导致引用位置内存被重写,引起错误。

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理