Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
From: REH (bogus_at_nowhere.net)
Date: 03/28/05
- Next message: jstevanus_at_gmail.com: "Need help with Pointers"
- Previous message: Andrew McDonagh: "Re: void pointers"
- In reply to: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- Next in thread: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- Reply: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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();
- Next message: jstevanus_at_gmail.com: "Need help with Pointers"
- Previous message: Andrew McDonagh: "Re: void pointers"
- In reply to: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- Next in thread: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- Reply: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|