Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)

From: REH (bogus_at_nowhere.net)
Date: 03/28/05


Date: Mon, 28 Mar 2005 12:03:52 -0500


"Ioannis Vranos" <ivr@remove.this.grad.com> wrote in message
news:1112022773.497341@athnrd02...
> In C++ you can always do:
>
> #include <new>
>
>
> class SomeClass
> {
> };
>
>
> void somefunc()
> {
> unsigned char obj[sizeof(SomeClass)];
>
> SomeClass *p= new(obj)SomeClass;
>
> delete p;
> }
>
>
> as also:
>
>
> #include <new>
>
>
> class SomeClass
> {
> };
>
>
> SomeClass *somefunc()
> {
> static unsigned char obj[sizeof(SomeClass)];
>
> return new(obj)SomeClass;
> }
>
>
> int main()
> {
> SomeClass *p= somefunc();
>
> delete p;
> }
>
>
> Here the object is created in the stack.
>
Another problem with this is you cannot use delete on a pointer returned
from placement new. You must instead call the destructor directly:
p->~SomeClass();



Relevant Pages