How to use structs for RAII?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Jan 22 16:14:04 PST 2011
A workaround:
import std.stdio;
import std.exception;
struct A
{
int x;
this(void* none)
{
if (none !is null)
{
enforce(0, "Tried to pass a parameter to A's constructor");
}
writeln("in constructor");
// construction from here..
x = 5;
}
}
void main()
{
auto a = A(null);
}
I think that would be safe, and closest to a "default" constructor.
More information about the Digitalmars-d-learn
mailing list