digitalmars.D - Protection attributes does not work in accordance with docs
- nail (31/31) Jan 26 2005 Hi all,
- nail (4/35) Jan 28 2005 No replies. Hm...
- Ben Hinkle (2/5) Jan 28 2005 I think it is a compiler bug. It works if the class Nested is moved to t...
- David L. Davis (53/56) Jan 28 2005 nail: If you comment out the "private:" in the Nested class it seems to ...
- nail (2/4) Jan 28 2005 If I'll comment it foo would be avaible from other modules. That's not w...
- David L. Davis (63/67) Jan 28 2005 nail: With a second thought, this may not be an error after all, but a s...
- Carlos Santander B. (7/51) Jan 31 2005 Is it me, or this is ambiguous? It should be one thing, or the other
Hi all, Here is the quote from http://www.digitalmars.com/d/attribute.html: Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class. So the question - why following code does not compiles: module test; class A { public class Nested { private: uint someMember; } this() { nest = new Nested(); } void foo() { nest.someMember = 10; // error here } private: Nested nest; } int main ( char [] [] args ) { A a = new A(); a.foo(); return 0; } Error is: class rame.test.A.Nested member someMember is not accessible
Jan 26 2005
In article <ct7udp$1dor$1 digitaldaemon.com>, nail says...Hi all, Here is the quote from http://www.digitalmars.com/d/attribute.html: Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class. So the question - why following code does not compiles: module test; class A { public class Nested { private: uint someMember; } this() { nest = new Nested(); } void foo() { nest.someMember = 10; // error here } private: Nested nest; } int main ( char [] [] args ) { A a = new A(); a.foo(); return 0; } Error is: class rame.test.A.Nested member someMember is not accessibleNo replies. Hm... Is this question so stupid? I can not understand is it a bug in dmd or my misunderstood.
Jan 28 2005
No replies. Hm... Is this question so stupid? I can not understand is it a bug in dmd or my misunderstood.I think it is a compiler bug. It works if the class Nested is moved to the top level.
Jan 28 2005
In article <ctd3fi$240l$1 digitaldaemon.com>, nail says...No replies. Hm... Is this question so stupid? I can not understand is it a bug in dmd or my misunderstood.nail: If you comment out the "private:" in the Nested class it seems to work just fine...but since you should be able to place the "private" keyword here if you'd like to, I'd say it's a bug. Also below I've added a fooprint function to verify that I am indeed getting the correct value back. output: C:\dmd>bin\dmd test.d C:\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi; C:\dmd>test nest.someMember=10 David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Jan 28 2005
nail: If you comment out the "private:" in the Nested class it seems to work just fine...If I'll comment it foo would be avaible from other modules. That's not what I want. So if it is a bug, hope Walter will keep it in mind.
Jan 28 2005
In article <ctdt81$2k1$1 digitaldaemon.com>, nail says...nail: With a second thought, this may not be an error after all, but a scoping issue. Since the nested class is hiding it's private members from the parent class (I think this is normal), and since the nested class can't be inherted...you can't use the "protected" keyword, which only leaves public. Below I've added getValue() and setValue() methods to the nested class, which I think does what you're looking for. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"nail: If you comment out the "private:" in the Nested class it seems to work just fine...If I'll comment it foo would be avaible from other modules. That's not what I want. So if it is a bug, hope Walter will keep it in mind.
Jan 28 2005
nail wrote:Hi all, Here is the quote from http://www.digitalmars.com/d/attribute.html: Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class.Is it me, or this is ambiguous? It should be one thing, or the other thing, but whatever it is, it should be explicitly stated. Or maybe I'm just mis-reading it.So the question - why following code does not compiles: module test; class A { public class Nested { private: uint someMember; } this() { nest = new Nested(); } void foo() { nest.someMember = 10; // error here } private: Nested nest; } int main ( char [] [] args ) { A a = new A(); a.foo(); return 0; } Error is: class rame.test.A.Nested member someMember is not accessibleI suggest you to post a bug report in the bugs ng. _______________________ Carlos Santander Bernal
Jan 31 2005