关于SetItemDataPtr,该如何解决

关于SetItemDataPtr
CComboBox::SetItemDataPtr
int SetItemDataPtr( int nIndex, void* pData );

Return Value

CB_ERR if an error occurs.

Parameters

nIndex

Contains a zero-based index to the item.

pData

Contains the pointer to associate with the item.

Remarks

Sets the 32-bit value associated with the specified item in a combo box to be the specified pointer (void*). This pointer remains valid for the life of the combo box, even though the item’s relative position within the combo box might change as items are added or removed. Hence, the item’s index within the box can change, but the pointer remains reliable.

这是MSDN给出的解释

在使用的时候老师重新构造了一个变量来存放地址

CString tel="12345";
m_tel.SetItemDataPtr(0,new CString (tel));
编译通过,可以运行

但是我换了一种方式

CString tel="12345";
CString *mem=&tel;

m_tel.SetItemDataPtr(0,mem);

编译还是可以通过 但是运行缺出错, 不知原因何在 忘各位老师帮帮忙

------解决方案--------------------
tel 是局部变量,出了作用域会被析构
------解决方案--------------------
自己new一个,放到堆里,
如果不new的话,放栈里一出函数,就释放掉了