On Mon, 12 Jan 2015 19:29:53 +0000 jmh530 via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
the proper answer is too long to write (it will be more an article that a forum answer ;-), so i'll just give you some directions: import std.typecons; { auto b = scoped!B(); // `auto` is important here! ... } `scoped!` allocating class instance *on* *stack*, and automatically calls destructor when object goes out of scope. but you'd better consider using struct for such things, as struct are stack-allocated by default (unlike classes, which are reference type and should be allocated manually). there is a big difference between `class` and `struct` in D, much bigger that in C++ (where it's only about default protection, actually).
signature.asc
Description: PGP signature