November 14, 2005 Compiler Issue when using GDC on Cygwin | ||||
---|---|---|---|---|
| ||||
I hope this is the proper place to post this. I noticed that the compiler ran fine with this bit of code. import std.c.stdio; class Base { private: int x; } class Sub: Base { public: void Write() { printf( "X: %d\n", x ); } } void main() { Sub ob; ob.Write(); } The issue I have is that the Sub class is allowed to access private variables from the base class. I also noted that this reverts to the correct behavior when these classes are separated into different module files. Thank you. --------------- Adam Juersivich |
November 14, 2005 Re: Compiler Issue when using GDC on Cygwin | ||||
---|---|---|---|---|
| ||||
Posted in reply to lp_fury | lp_fury@hotmail.com wrote:
> I hope this is the proper place to post this. I noticed that the compiler ran
> fine with this bit of code.
>
> import std.c.stdio;
>
> class Base
> {
> private:
> int x;
> }
>
> class Sub: Base
> {
> public:
> void Write()
> {
> printf( "X: %d\n", x );
> }
> }
>
> void main()
> {
> Sub ob;
> ob.Write();
> }
>
> The issue I have is that the Sub class is allowed to access private variables
> from the base class. I also noted that this reverts to the correct behavior
> when these classes are separated into different module files. Thank you.
>
> ---------------
> Adam Juersivich
This is correct behavior - classes in the same module are implicitely each other's "friends" (see c++, friend keyword). I think this detail can be found in the D language manual. However, currently there's a bug in the currect module member access implementation. See the d.bugs newsgroup for details.
|
Copyright © 1999-2021 by the D Language Foundation