D - Nesting oddity
- Patrick Down (35/35) May 07 2002 I've compiled and run the following program in D.
- Patrick Down (4/6) May 07 2002 Sorry I ment to say that outer class is just a namespace
- Walter (3/9) May 08 2002 I think you found a compiler bug. -Walter
I've compiled and run the following program in D. It prints: Result = 14 class Foo { private int Fred() { return 14; } class Bar // 1 { int Barney() { return Fred(); // 2 } } } int main(char[][] args) { Foo.Bar obj = new Foo.Bar(); // 3 printf("Result = %d\n",obj.Barney()); return 0; } Now this is a little weard because it expected one of three compiler errors: 1. Can't nest classes 2. The C++ way: nested classes are just a way of scoping names. Function Fred is undefined in Barney. Nested classes in C++ always seemed a little pointless to me. 3. The Java way: Nested classes are inner classes. You can't create a Foo.Bar with having a Foo first or Bar needs to be static. I like Java's inner classes.
May 07 2002
Patrick Down <pat codemoon.com> wrote in news:Xns9207B094D64E1patcodemooncom 63.105.9.61:2. The C++ way: nested classes are just a way of scoping names.Sorry I ment to say that outer class is just a namespace for the inner one.
May 07 2002
I think you found a compiler bug. -Walter "Patrick Down" <pat codemoon.com> wrote in message news:Xns9207B1C2F6F86patcodemooncom 63.105.9.61...Patrick Down <pat codemoon.com> wrote in news:Xns9207B094D64E1patcodemooncom 63.105.9.61:2. The C++ way: nested classes are just a way of scoping names.Sorry I ment to say that outer class is just a namespace for the inner one.
May 08 2002