www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - access to private members of nested classes

reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----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-----
Apr 06 2005
next sibling parent reply Ant <Ant_member pathlink.com> writes:
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
Apr 06 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----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-----
Apr 06 2005
parent reply Ant <Ant_member pathlink.com> writes:
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
Apr 06 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ant wrote:
 In article <b39di2-bk6.ln1 lnews.kuehne.cn>, Thomas Kuehne says...

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.
Apr 06 2005
parent Ant <Ant_member pathlink.com> writes:
In article <d311bt$2fdj$1 digitaldaemon.com>, Stewart Gordon says...
Ant wrote:
 In article <b39di2-bk6.ln1 lnews.kuehne.cn>, Thomas Kuehne says...

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
Apr 06 2005
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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.
Apr 06 2005