Topic: Placement Delete
Author: clamage@taumet.eng.sun.com (Steve Clamage)
Date: 2000/01/31 Raw View
Hi,
There seems an oversight in the C++ Standard. I can find the sections
where the declarations for a placement-delete operator are desribed
but I cannot find a place where the syntax used to invoke placement
delete is specified.
Am I correct in that no such section exists? Or did I miss it somewhere?
Can I assume the invocation syntax to be parallel to placement new? As in:
A* a = new (arg1,arg2)A;
delete (arg1,arg2)a;
Any insight would be appreciated,
- Itai
-------------------------------------
Itai Danan
idanan@ibm.net
-------------------------------------
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Steve Clamage <stephen.clamage@sun.com>
Date: 2000/01/31 Raw View
Itai Danan wrote:
>
> There seems an oversight in the C++ Standard. I can find the sections
> where the declarations for a placement-delete operator are desribed
> but I cannot find a place where the syntax used to invoke placement
> delete is specified.
There is no such syntax, and it isn't an oversight. The obvious
syntax
delete (<args>) ptr;
is ambiguous. Stroustrup could not find a reasonable syntax for a
placement-delete, and the C++ Committee couldn't either.
The best you can do is to destroy the object and call the "placement"
version of operator delete directly. Example:
void* operator new(size_t sz, const T& t) { ... }
void operator delete(void* ptr, const T& t) { ... }
T T_obj;
U* p = new (T_obj) U;
...
p->~U(); // destroy the heap object
operator delete(p, T_object); // recycle the storage
--
Steve Clamage, stephen.clamage@sun.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]