Compiler error with static vars/functions
Oliver Plow
saxo123 at gmx.de
Thu Feb 9 05:57:08 PST 2012
Hello,
I'm fighting with a strange compiler error. This here compiles and runs fine:
---------- main.d -------------
class Foo
{
static int z = 4;
static int bar() { return 6; }
int foobar() { return 7; }
}
int main(string[] argv)
{
writeln(Foo.z);
writeln(Foo.bar()); // produces 6
Foo f;
writeln(f.bar()); // produces 6;
writeln(f.foobar());
return 0;
}
Whereas this does not compile:
---------- main.d -------------
import Foo;
int main(string[] argv)
{
writeln(Foo.z); // Error: undefined identifier module Foo.z
writeln(Foo.bar()); // Error: undefined identifier module Foo.bar
Foo f;
writeln(f.bar());
writeln(f.foobar());
return 0;
}
---------- Foo.d ----------
class Foo
{
public static int z = 4;
public static int bar() { return 6; }
public int foobar() { return 7; }
}
This is a bit strange for me. Apparently, must be some kind of import problem importing Foo. But I don't see how ...
Thanks for any hints.
Cheers, Oliver
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
More information about the Digitalmars-d-learn
mailing list