Car*_*ary 2 c++ mfc visual-c++-6
我读的源代码CString中的MFC.我对构造函数的实现方式很好奇CString::CString(LPCTSTR lpsz).
在我的理解,通过复制指定的字符串之前lpsz,只需要检查是否lpsz是NULL更没有必要与检查,如果结合HIWORD(lpsz)是NULL.
有没有MFC人经过这里并愿意给出一些解释?
CString::CString(LPCTSTR lpsz)
{
Init();
if (lpsz != NULL && HIWORD(lpsz) == NULL)
{
UINT nID = LOWORD((DWORD)lpsz);
if (!LoadString(nID))
TRACE1("Warning: implicit LoadString(%u) failed\n", nID);
}
else
{
int nLen = SafeStrlen(lpsz);
if (nLen != 0)
{
AllocBuffer(nLen);
memcpy(m_pchData, lpsz, nLen*sizeof(TCHAR));
}
}
}
Run Code Online (Sandbox Code Playgroud)