要解决这个问题可以去查源码,
\VC98\MFC\Include\AFXCOLL.INL的37行_AFXCOLL_INLINE int CByteArray::Add(BYTE newElement)
{ int nIndex = m_nSize;
SetAtGrow(nIndex, newElement);
return nIndex; }
看见了吗?
从m_nSize开始向后SetAtGrow,而
VC98\MFC\SRC\ARRAY_B.CPP的88行又写了一个
m_nSize = nNewSize;
这是SetSize的源码。自己编写程序时,
可以用SetAtGrow()来解决。
同时维护一个从0自加的变量。[email protected]