Topic: Revise the simulation of the delete expression
Author: "Dean Jiang" <deanjiang@hotmail.com>
Date: Mon, 13 May 2002 17:34:58 GMT Raw View
Sorry, there are a mistake in my text:
> delete(pAllocator) pBase; //ill-form usage of delete expression
> In many case we can simulate the action of delete:
> pBase->~CType();
> CType* pType=dynamic_cast<CType*>(pBase);
> operator delete(pType, pAllocator);
It SHOULD be:
delete(pAllocator) pBase; //ill-form usage of delete expression
Sometimes we can simulate the action of placement delete, but sometimes
can not, according to the CBaseType class:
[If CBaseType have at least one virtual function, or say it has a
v-table]
pBase->~CBaseType();
void* pVoid=dynamic_cast<void*>(pBase);
operator delete(pVoid, pAllocator);
[If CBaseType have no virtual function, and dynamic type of object is
known as CType, and CType inherit CBaseType only one times.]
pBase->~CBaseType();
CType* pType=static_cast<CType*>(pBase);
operator delete(pType, pAllocator);
[In any other case, the simulation is difficult if not impossible.]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]