namespace (for export)
Daniel Murphy
yebblies at nospamgmail.com
Thu Nov 25 05:41:27 PST 2010
I might be off track, but I think I know what you're getting at.
You want to define a set of module scope variable that are initialized when
the program starts up:
eg. A struct that stores information loaded from a configuration file (can't
be done at compile time)
--------
module foo;
struct ConfigData
{
...
}
ConfigData myData = loadFromFile();
--------
This then doesn't work because loadFromFile can't be called at compile time,
and therefore can't be used to initialize a global.
You've then done:
--------
module foo;
struct ConfigData
{
...
}
static this()
{
ConfigData myData = loadFromFile();
}
--------
Which works, and runs on program startup, but doesn't let you access
anything defined inside the static this from another module.
If I'm right so far, then the solution is to seperate the definition and the
initialization:
--------
module foo;
struct ConfigData
{
...
}
ConfigData myData;
static this()
{
myData = loadFromFile();
}
--------
In order to get the best of both worlds...
More information about the Digitalmars-d-learn
mailing list