C ++ initialization problem structure

 

The structure is used in CString type variable, initialization using memset is wrong

The reason: m_strTemp address is assigned a null pointer, not the contents of the m_strTemp assignment is empty, so the subsequent use on the wrong

as follows:

struct Test
{
CString m_strTemp;
int m_nTemp;
bool m_bTemp;
Test()
{
memset(this,0,sizeof(Test));
}
};
Test TempStr;
TempStr.m_strTemp = _T("");

If the structure is initialized with a string like, we suggested char [] array may be initialized using memset

Guess you like

Origin www.cnblogs.com/zhangbing888823/p/11087816.html