How to include??
Ary Manzana
ary at esperanto.org.ar
Thu Oct 18 12:38:26 PDT 2007
This compiles, runs, and outputs "hola" as expected:
---
class X {
import std.stdio;
void foo() {
writefln("hola");
}
}
void main() {
(new X()).foo();
}
---
Even more, if you move the foo function outside X, it doesn't compile
because it can't find "writefln". If I remember correctly from what I've
seen in DMD's code, the import loads the imported symbols into the
symbol table of the current scope (X, in this case). So... it works. :-)
Bruno Medeiros wrote:
> BCS wrote:
>> Reply to Ary,
>>
>>> BCS wrote:
>>>
>>>> import is only allowed at module scope, not in a class or function or
>>>> sutch.
>>>>
>>> IIRC import is allowed in classes.
>>
>> Oh. it is? Didn't know that
>>
>
> It is "allowed" there (no compiler error) but it has no effect there. It
> only has effect at module scope.
>
>
More information about the Digitalmars-d-learn
mailing list