[Issue 2070] DMD should allow easy creation of stack-allocated classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 12 06:59:42 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2070





------- Comment #2 from davidl at 126.com  2008-08-12 08:59 -------
you misunderstand post expression.
delete new C() will only give you an invalid pointer, if it really behaves like
a post expression.

1. new C() ->  push the pointer to the stack
2. delete C() -> delete the object
3. call the function 

it's not working in the way:
1. new C()
2. call the func
3. delete C()


and from the spec, scope attribute is only for RAII
http://www.digitalmars.com/d/1.0/attribute.html#scope

"The scope attribute is used for local variables and for class declarations.
For class declarations, the scope attribute creates a scope class. For local
declarations, scope implements the RAII (Resource Acquisition Is
Initialization) protocol. This means that the destructor for an object is
automatically called when the reference to it goes out of scope. The destructor
is called even if the scope is exited via a thrown exception, thus scope is
used to guarantee cleanup."

but from a quick test, it's on the stack! why the spec didn't mention this?


-- 



More information about the Digitalmars-d-bugs mailing list