Thread overview | |||||
---|---|---|---|---|---|
|
July 08, 2004 BaseClass.member is not accessible | ||||
---|---|---|---|---|
| ||||
In test.d: class Foo { protected int bar; } In main.d: import test; class Bar: Foo { this() { //Foo.bar = 2; // class Foo member bar is not accessible bar = 2; // Works } } The commented assignment should work but doesn't. |
July 08, 2004 Re: BaseClass.member is not accessible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote:
> In test.d:
>
> class Foo
> {
> protected int bar;
> }
>
>
> In main.d:
>
> import test;
> class Bar: Foo
> {
> this()
> {
> //Foo.bar = 2; // class Foo member bar is not accessible
> bar = 2; // Works
> }
> }
>
>
> The commented assignment should work but doesn't.
The compiler is griping (I think) because it thinks you're trying to assign to a static member of Foo. You can do this:
class Bar: Foo
{
this()
{
super.bar = 2;
}
}
|
July 09, 2004 Re: BaseClass.member is not accessible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:cckioe$3od$1@digitaldaemon.com... > Vathix wrote: > > In test.d: > > > > class Foo > > { > > protected int bar; > > } > > > > > > In main.d: > > > > import test; > > class Bar: Foo > > { > > this() > > { > > //Foo.bar = 2; // class Foo member bar is not accessible > > bar = 2; // Works > > } > > } > > > > > > The commented assignment should work but doesn't. > > The compiler is griping (I think) because it thinks you're trying to assign to a static member of Foo. You can do this: > > class Bar: Foo > { > this() > { > super.bar = 2; > } > } > I don't think so. This is a recently added feature. It lets you access one of the base's [instance] members since super can't work past one level. |
Copyright © 1999-2021 by the D Language Foundation