Fri, 05 Feb 2010 16:03:22 -0800, Walter Bright wrote: > retard wrote: >> Fri, 05 Feb 2010 13:24:44 -0800, Walter Bright wrote: >> >>> retard wrote: >>>> {protection-attr} == perhaps one of these >>>> {public|protected|package| >>>> private} - I have no effing clue what this does >>> It actually does the same thing as it does in C++ (with the addition >>> of package). >> >> I see. I only noticed now that dmd actually does enforce this rule in >> some cases. Unfortunately the rule is checked only statically when it >> can be checked. If you access the object via base class or interface >> type reference, a runtime check is not made unlike in c++. > > There must be some misunderstanding here. There are no runtime access > checks in C++, it is all done statically at compile time.
Thanks. It seems I have been testing this with a buggy c++ compiler or can't remember what was the problem previously. I now tried with gcc 4.4.3 and this is how D and C++ differ: --- class Foo { public: void bar() {} }; class Bar : private Foo { }; int main() { Foo *a = new Bar(); a->bar(); } test.cpp: In function ‘int main()’: test.cpp:10: error: ‘Foo’ is an inaccessible base of ‘Bar’ --- module m1; class Foo { public void bar() {} } class Bar : private foo { } module m2; import m1; void main() { Foo a = new Bar(); a.bar(); } // compiles and runs just fine // Changing the 'Foo a = ...' into 'Bar a = ...' makes this an error