Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
April 06, 2005 access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 # class A{ # class B{ # private char c; # } # # void test(B b){ # b.c='2'; /* ! */ # } # } dmd-0.119: class A.B member c is not accessible http://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. Am I missing something or should the code above compile? Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCU8iK3w+/yD4P9tIRAl9yAJ9bEoCFq4aoxBYK9HNyt15RGPLyngCdE2eI g2I9l9OaFBbNL0Cj9JFl2nQ= =TWeR -----END PGP SIGNATURE----- |
April 06, 2005 Re: access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | In article <attci2-qul.ln1@lnews.kuehne.cn>, Thomas Kuehne says... > > >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > ># class A{ ># class B{ ># private char c; ># } ># ># void test(B b){ ># b.c='2'; /* ! */ ># } ># } > >dmd-0.119: >class A.B member c is not accessible > >http://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. > >Am I missing something or should the code above compile? > It should NOT compile. "the enclosing" class means B. Ant |
April 06, 2005 Re: access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ant schrieb am Wed, 6 Apr 2005 14:30:43 +0000 (UTC): > In article <attci2-qul.ln1@lnews.kuehne.cn>, Thomas Kuehne says... >> >> >>-----BEGIN PGP SIGNED MESSAGE----- >>Hash: SHA1 >> >># class A{ >># class B{ >># private char c; >># } >># >># void test(B b){ >># b.c='2'; /* ! */ >># } >># } >> >>dmd-0.119: >>class A.B member c is not accessible >> >>http://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. >> >>Am I missing something or should the code above compile? >> > > It should NOT compile. > "the enclosing" class means B. "or members and functions in the same module" A and B are in the same module. the code below compiles # class B{ # private char c; # } # # void test(B b){ # b.c='2'; # } Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCU/VL3w+/yD4P9tIRAn1VAJ9Tl6hrd3NrEr8htKS8H6lxedQdfwCfXoX2 VravBqz8tkgn3D+tm0chWAs= =MDkD -----END PGP SIGNATURE----- |
April 06, 2005 Re: access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | Thomas Kuehne wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > # class A{ > # class B{ > # private char c; > # } > # > # void test(B b){ > # b.c='2'; /* ! */ > # } > # } > > dmd-0.119: > class A.B member c is not accessible I thought this bug had been fixed, but apparently not. > http://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. > > Am I missing something or should the code above compile? Yes. Moreover, it's a prime example of the usefulness of private stuff being accessible to the module. It's just a slightly cut-down version of private_02 in DStress. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
April 06, 2005 Re: access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | In article <b39di2-bk6.ln1@lnews.kuehne.cn>, Thomas Kuehne says... > > >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Ant schrieb am Wed, 6 Apr 2005 14:30:43 +0000 (UTC): >> In article <attci2-qul.ln1@lnews.kuehne.cn>, Thomas Kuehne says... >>> >>> >>>-----BEGIN PGP SIGNED MESSAGE----- >>>Hash: SHA1 >>> >>># class A{ >>># class B{ >>># private char c; >>># } >>># >>># void test(B b){ >>># b.c='2'; /* ! */ >>># } >>># } >>> >>>dmd-0.119: >>>class A.B member c is not accessible >>> >>>http://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. >>> >>>Am I missing something or should the code above compile? >>> >> >> It should NOT compile. >> "the enclosing" class means B. > >"or members and functions in the same module" >A and B are in the same module. > >the code below compiles ># class B{ ># private char c; ># } ># ># void test(B b){ ># b.c='2'; ># } !!!! it's a pitty, it shouldn't. and change the docs. oh well... Ant |
April 06, 2005 Re: access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | Ant wrote: > In article <b39di2-bk6.ln1@lnews.kuehne.cn>, Thomas Kuehne says... <snip> >>the code below compiles >># class B{ >># private char c; >># } >># # void test(B b){ >># b.c='2'; >># } > > !!!! > > it's a pitty, it shouldn't. and change the docs. > oh well... Any particular reason you don't like this feature? And if we broke plenty of existing code by changing it, how would you suggest rewriting this? http://www.digitalmars.com/d/cpptod.html#friends Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
April 06, 2005 Re: access to private members of nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | In article <d311bt$2fdj$1@digitaldaemon.com>, Stewart Gordon says... > >Ant wrote: >> In article <b39di2-bk6.ln1@lnews.kuehne.cn>, Thomas Kuehne says... ><snip> >>>the code below compiles >>># class B{ >>># private char c; >>># } >>># >>># void test(B b){ >>># b.c='2'; >>># } >> >> !!!! >> >> it's a pitty, it shouldn't. and change the docs. >> oh well... > >Any particular reason you don't like this feature? > >And if we broke plenty of existing code by changing it, how would you suggest rewriting this? > >http://www.digitalmars.com/d/cpptod.html#friends You're right. I forget that. Somebody explain it to me on these groups but obviously my understanding is only supperficial, and I don't use it at all. My limitation, sorry. Ant |
Copyright © 1999-2021 by the D Language Foundation