Need help with simple event framework

Ali Çehreli acehreli at yahoo.com
Sat Nov 19 16:03:36 PST 2011


On 11/19/2011 01:22 PM, Tano Sakaria wrote:
> I'm sorry, but I don't understand.
>
> How can I use "new" in conjunction with a pointer? "new" creates an
> object, but don't I need a pointer to said object instead for my
> linked list?

Without seeing the original code, foo() below returns a pointer to an 
object allocated on the heap:

struct S
{}

S * foo()
{
     S * p = new S;
     return p;
}

void main()
{
     S * p = foo();
}

That object belongs to the D runtime and may be destroyed at an 
unspecified time when there are no more references to it.

Ali


More information about the Digitalmars-d-learn mailing list