Posted on 2009-10-24 02:05
oyjpart 閱讀(2765)
評論(0) 編輯 收藏 引用 所屬分類:
程序設(shè)計(jì)
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自動擴(kuò)容去了,結(jié)果導(dǎo)致引用位置內(nèi)存被重寫,引起錯(cuò)誤。