Thread overview | |||||
---|---|---|---|---|---|
|
May 07, 2002 Nesting oddity | ||||
---|---|---|---|---|
| ||||
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 Re: Nesting oddity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | 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 Re: Nesting oddity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | 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. > |
Copyright © 1999-2021 by the D Language Foundation