Compiler error with static vars/functions

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 9 11:18:07 PST 2012


On Thursday, February 09, 2012 14:57:08 Oliver Plow wrote:
> Hello,
> 
> I'm fighting with a strange compiler error. This here compiles and runs
> fine:
> 
[snip]
>
> This is a bit strange for me. Apparently, must be some kind of import
> problem importing Foo. But I don't see how ...

It's because you named both your module and type Foo. So, when you import Foo, 
Foo.z is a module-level symbol in Foo (which does not exist). You'd need to do 
Foo.Foo.z. If your module were named something completele different (e.g. 
xyzzy), then Foo.z would then be referring to your class Foo's z variable, and 
it would work.

Normally, it's considered good practice to give modules names which are all 
lowercase (particularly since some OSes aren't case-sensitive for file
operations). Renaming your module to foo should fix your problem.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list