Inheritance problem
%u
unknown at unknown.com
Fri Feb 11 13:29:01 PST 2011
== Auszug aus Steven Schveighoffer (schveiguy at yahoo.com)'s Artikel
> On Fri, 11 Feb 2011 16:14:31 -0500, %u <unknown at unknown.com> wrote:
> > == Auszug aus Steven Schveighoffer (schveiguy at yahoo.com)'s Artikel
> >
> > Thanks, but what about the following:
> >
> > import std.stdio : writeln;
> >
> > class a {
> >
> > public this(int v) {
> > myVar = v;
> > }
> >
> > protected int myVar;
> >
> > }
> >
> > class b : a {
> >
> > private a[] moreInstances;
> >
> > this(int v, int[] vars...) {
> > super(v);
> > moreInstances ~= this;
> >
> > foreach(int cur; vars) {
> > moreInstances ~= new a(cur);
> > }
> > }
> >
> > int getVar() {
> > return moreInstances[1].myVar;
> > }
> >
> > }
> >
> > void main(string[] args) {
> > b exp = new b(0, 1, 2);
> > writeln(exp.getVar());
> > }
> >
> > This compiles fine and prints the number 1. myVar is also
protected
> > in class a, I also call myVar in the getVar()-method of class b.
> Any code can access any members defined in the current module,
regardless
> of access attributes (that rule is outlined in the link I sent, I
just
> didn't quote that part). You have to split this into multiple
modules to
> see the other rules take effect.
> -Steve
Ah, okay... this means I have to Texture and Animation into one
module. Thanks a lot!
More information about the Digitalmars-d-learn
mailing list