首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

delete this 有关问题

2012-02-12 
delete this 问题为什么delete this以后还可以访问this指针?应该是不可以访问的呀!附上几行代码:void CWin

delete this 问题
为什么delete this以后还可以访问this指针?应该是不可以访问的呀!附上几行代码:
void CWinThread::Delete()
{
  if (m_bAutoDelete)
  delete this;
}

CWinThread::~CWinThread()
{
  if (m_hThread != NULL)
  CloseHandle(m_hThread);
  AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
  if (pState->m_pCurrentWinThread == this)
  pState->m_pCurrentWinThread = NULL;
}


[解决办法]
在析构函数里面还是可以使用this指针的。不过等析构函数调用完在使用this指针就没什么意义了。
[解决办法]
呵呵,因为delete this;是先调用析构函数,再释放内存,所以在析构函数里对象还是完整的。

热点排行