Posted on 2009-10-24 02:05
oyjpart 阅读(2755)
评论(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自动扩容去了,结果导致引用位置内存被重写,引起错误。