nested class inheritance

2011-05-31 Thread Michael Shulman
Hi, I have a class which defines a nested class: class Outer1 { class Inner1 { } } Now I want to inherit from Outer1, to modify its behavior in a way which also involves modifying the behavior of the corresponding inner objects. My first instinct was to write class Outer2 : Outer1 { class

Re: nested class inheritance

2011-05-31 Thread Michael Shulman
On Tue, May 31, 2011 at 2:24 PM, Simen Kjaeraas wrote: >> I have thought of a workaround with 'alias this': >> >> class Outer2 : Outer1 { >>  class Inner2 { >>    Inner1 _self; >>    alias _self this; >>    this() { >>      _self = this.outer.new Inner1(); >>    } >>  } >> } >> >> This seems to wo

private method in interface

2011-06-02 Thread Michael Shulman
Hi, The following code fails the linker, complaining about an undefined reference to 'foo': interface A { private int foo(); } class B { int bar(A x) { return x.foo(); } } void main() { } But if I remove the 'private' qualifier on 'foo', then it succeeds. Shouldn't B.bar() be able to acc

Re: private method in interface

2011-06-02 Thread Michael Shulman
On Thu, Jun 2, 2011 at 10:31 AM, Steven Schveighoffer wrote: > Private methods are non-virtual, so I'm pretty sure they are not supposed to > be allowed in an interface. > > But I suppose private could also mean private final, in which case you have > to provide an implementation for foo in the in

Re: private method in interface

2011-06-02 Thread Michael Shulman
On Thu, Jun 2, 2011 at 12:20 PM, Jonathan M Davis wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=4542 > http://d.puremagic.com/issues/show_bug.cgi?id=2051 Thank you! I think this answers my question completely; I just need to change "private" to "protected". Is there a place on the web

Re: private method in interface

2011-06-02 Thread Michael Shulman
Thanks! On Thu, Jun 2, 2011 at 2:36 PM, Jonathan M Davis wrote: > On 2011-06-02 12:59, Michael Shulman wrote: >> On Thu, Jun 2, 2011 at 12:20 PM, Jonathan M Davis > wrote: >> > http://d.puremagic.com/issues/show_bug.cgi?id=4542 >> > http://d.puremagic.com/issues/sh

Re: private method in interface

2011-06-03 Thread Michael Shulman
On Thu, Jun 2, 2011 at 11:55 PM, Jonathan M Davis wrote: > I don't really like the idea of private functions being virtual > by default though, so maybe your suggestion would be a good one. Speaking as a newbie with very little D experience, the idea of private functions being non-virtual would m

Re: private method in interface

2011-06-03 Thread Michael Shulman
On Fri, Jun 3, 2011 at 11:22 AM, Jonathan M Davis wrote: >> However, given that in D, 'private' only means restricted to a >> *module*, it's less clear to me why private functions should be >> singled out as non-virtual. I might want certain methods to be >> accessible only within a given module,

Re: private method in interface

2011-06-03 Thread Michael Shulman
On Fri, Jun 3, 2011 at 1:02 PM, Jonathan M Davis wrote: > And if you don't know about NVI, having a > virtual private function is just plain weird. Well, it makes perfect sense to me, once given that in D, 'private' allows access from anywhere in the same module, rather than only in the defining

Re: private method in interface

2011-06-03 Thread Michael Shulman
On Fri, Jun 3, 2011 at 3:07 PM, Jonathan M Davis wrote: > I'd suggest opening a bug report. Okay, will do. > Regardless, I would have hoped that you'd get an error at compile > time about overriding a non-virtual function if package is > non-virtual It appears that overriding a non-virtual, non

Re: private method in interface

2011-06-03 Thread Michael Shulman
The bug report appears to already exist: http://d.puremagic.com/issues/show_bug.cgi?id=3258 On Fri, Jun 3, 2011 at 3:07 PM, Jonathan M Davis wrote: > On 2011-06-03 14:55, Michael Shulman wrote: >> On Fri, Jun 3, 2011 at 1:02 PM, Jonathan M Davis > wrote: >> > And if you

Re: private method in interface

2011-06-03 Thread Michael Shulman
On Fri, Jun 3, 2011 at 8:54 PM, Jonathan M Davis wrote: > Try to compile with -w. My guess is that you will get a compiler error. Nope.

'this' in base class out contract

2011-06-04 Thread Michael Shulman
Why does the following code fail the assertion? class A { void foo() out { assert(stored is this); } body { } } A stored; class B : A { void foo() { stored = this; } } void main () { B x = new B(); x.foo(); }

Re: 'this' in base class out contract

2011-06-04 Thread Michael Shulman
On Sat, Jun 4, 2011 at 4:27 AM, bearophile wrote: >> x: 14e2fd0 >> Klass2.this: 14e2fd0 >> Klass1.this: 41d1b0 >> Klass1.stored: 14e2fd0 > > Note how much different are the two values of the object references. They may > even be in two different kinds of memory. Klass1.this may be in the static