digitalmars.D - Static members and access attribute
- Uriel (20/20) Oct 22 2008 I've found some strange behaviour with static members and haven't notice...
- Lars Kyllingstad (6/33) Oct 22 2008 No, that's the way it should be. You get the error because of the line
- Aarti_pl (9/47) Oct 22 2008 I am not sure about what you say... In Java you can access static
- Lars Kyllingstad (3/49) Oct 22 2008 OK, I didn't know that. Uriel, don't listen to me. :)
- Bruno Medeiros (6/33) Oct 24 2008 No, Foo is private, so you can't access it outside of the module where
- Sergey Gromov (4/35) Oct 24 2008 Of course it's not a bug that the commented-out part fails. It's a bug
- Bruno Medeiros (5/40) Oct 24 2008 Ah, duh, didn't notice that part, I agree.
I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?
Oct 22 2008
Uriel wrote:I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?No, that's the way it should be. You get the error because of the line obj.Foo = 2; Foo is not available for instances of A. There is only one (global) Foo, namely A.Foo. That's what static means. -Lars
Oct 22 2008
Lars Kyllingstad pisze:Uriel wrote:I am not sure about what you say... In Java you can access static members through objects - you get just warnings. As I said I am not sure how it is supposed to be in D. According to accessing private static member from another module - it is bug. Its already in bugzilla. BR Marcin Kuszczak (aarti_pl)I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?No, that's the way it should be. You get the error because of the line obj.Foo = 2; Foo is not available for instances of A. There is only one (global) Foo, namely A.Foo. That's what static means. -Lars
Oct 22 2008
Aarti_pl wrote:Lars Kyllingstad pisze:OK, I didn't know that. Uriel, don't listen to me. :) -LarsUriel wrote:I am not sure about what you say... In Java you can access static members through objects - you get just warnings. As I said I am not sure how it is supposed to be in D. According to accessing private static member from another module - it is bug. Its already in bugzilla.I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?No, that's the way it should be. You get the error because of the line obj.Foo = 2; Foo is not available for instances of A. There is only one (global) Foo, namely A.Foo. That's what static means. -Lars
Oct 22 2008
Uriel wrote:I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?No, Foo is private, so you can't access it outside of the module where it is defined (module a). -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Oct 24 2008
Fri, 24 Oct 2008 13:05:00 +0100, Bruno Medeiros wrote:Uriel wrote:Of course it's not a bug that the commented-out part fails. It's a bug that the first part of main() works.I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?No, Foo is private, so you can't access it outside of the module where it is defined (module a).
Oct 24 2008
Sergey Gromov wrote:Fri, 24 Oct 2008 13:05:00 +0100, Bruno Medeiros wrote:Ah, duh, didn't notice that part, I agree. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DUriel wrote:Of course it's not a bug that the commented-out part fails. It's a bug that the first part of main() works.I've found some strange behaviour with static members and haven't noticed anything about it in the documentation. module a; class A { private static int Foo; } import std.stdio; import a; void main() { A.Foo = 1; writeln(A.Foo); /* A obj = new A(); obj.Foo = 2; writeln(A.Foo); */ } Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible". Is this a bug?No, Foo is private, so you can't access it outside of the module where it is defined (module a).
Oct 24 2008