RAII trouble
Spacen Jasset via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 20 14:56:37 PST 2015
I have the following code in attempt to create an RAII object
wrapper, but it seems that it might be impossible. The problem
here is that FT_Init_FreeType is a static which is set at some
previous time to a function entry point in the FreeType library.
I could use a scope block, but would rather have a self contained
thing to do the work. Perhaps some sort of mixin is the other
solution?
The ideal would be to have a struct that can be placed inside a
function scope, or perhaps as a module global variable. Why does
Ft_Init_FreeType have to be read at compile time?
text.d(143,15): Error: static variable FT_Init_FreeType cannot be
read at compile time
text.d(174,43): called from here: initialise()
struct FreeType
{
@disable this();
static FreeType initialise()
{
return FreeType(0);
}
this(int)
{
int error = FT_Init_FreeType(&library); /// ERROR
enforce(!error);
}
alias library this;
~this()
{
FT_Done_FreeType(library);
}
FT_Library library;
}
FreeType freeType = FreeType.initialise();
More information about the Digitalmars-d-learn
mailing list