defining in a module symbols for export
spir
denis.spir at gmail.com
Tue Nov 23 02:41:58 PST 2010
On Mon, 22 Nov 2010 16:20:07 -0500
Jesse Phillips <jessekphillips+D at gmail.com> wrote:
> spir Wrote:
>
>
> > === mod.d ==
> > import std.stdio;
> >
> > struct S {
> > int i;
> > void speak() {writeln("i: ",this.i);}
> > }
> > === __trials__.d ===
> > import mod;
> >
> > auto s = S();
> > s.speak();
> > s.i = 1;
> > writeln(s.i);
> >
> > void main () {
> > }
>
> Others have answered how to initialize variables, but haven't explained the compilation error. A simple example of what you are doing wrong is:
>
> import std.stdio;
>
> writeln("foo");
>
> void main () {
> }
>
> How are you to execute writeln()? You probably wouldn't try this under normal conditions, but is what you are trying to do. You can place it in a static this constructor:
>
> import std.stdio;
>
> static this() { writeln("foo"); }
>
> void main () {
> }
>
> Note you can move the calls into main and it compiles fine:
>
> void main () {
> s.speak();
> s.i = 1;
> writeln(s.i);
> }
>
Right. Seems I may put the whole parser definition into static this(). I'll try it. Will work if symbols defined in there are available for export.
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
More information about the Digitalmars-d-learn
mailing list